[comp.sources.misc] v08i083: libhoward portability library, part 5 of 9

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (10/01/89)

Posting-number: Volume 8, Issue 83
Submitted-by: howard@dahlbeck.ericsson.se (Howard Gayle)
Archive-name: libhoward/part05

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
#		"End of archive 5 (of 9)."
# Contents:  getlin.3 getpwf.3 getpwf.c ma2u.c ma2ul.c malf.c
#   mkLibcLims.b msgfn.c smp.3 smp2l.c smp2u.c smp2ul.c
# Wrapped by howard@hasse on Mon Sep 25 07:08:10 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'getlin.3' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'getlin.3'\"
else
echo shar: Extracting \"'getlin.3'\" \(3505 characters\)
sed "s/^X//" >'getlin.3' <<'END_OF_FILE'
X.\" @(#)$Header: getlin.3,v 1.7 89/07/05 07:31:35 howard Exp $
X.TH GETLIN "3 -lhoward" "$Revision: 1.7 $" "Howard\'s C library" "Howard\'s C library"
X.SH NAME
Xgetlin, getlic \- read one line from a stream
X.SH SYNOPSIS
X.nf
X.BR "#include <" stdio.h ">"
X.BR "#include <" howard/port.h ">"
X.fi
X.LP
X.RI "bStrT getlin (" linebuf ", " bufsize ", " infile
X.RI ", " filename ", " lineno ", " tabwidth
X)
X.nf
X.RI "bStrT " linebuf ";"
X.BI "unsigned " bufsize;
X.RI "streamT " infile ";"
X.RI "bStrT " filename ";"
X.BI "unsigned *" lineno;
X.BI "unsigned " tabwidth;
X.fi
X.LP
X.RI "bStrT getlic (" linebuf ", " bufsize ", " infile
X.RI ", " filename ", " lineno ", " tabwidth
X.RI ", " comment ")"
X.nf
X.RI "bStrT " linebuf ";"
X.BI "unsigned " bufsize;
X.RI "streamT " infile ";"
X.RI "bStrT " filename ";"
X.BI "unsigned *" lineno;
X.BI "unsigned " tabwidth;
X.RI "rcharT " comment ";"
X.SH COPYRIGHT
XCopyright \(co 1989 Howard Lee Gayle
X.SH DESCRIPTION
X.I Getlin
Xattempts to read one line from the Standard I/O Library stream
X.I infile.
XOn success, the line is stored in the buffer to which
X.I linebuf
Xpoints.
XThe newline character at the end of the line is removed.
XThe line is NUL terminated.
XThe current line number, to which
X.I lineno
Xpoints, is incremented.
XIf
X.I tabwidth
Xis zero then tabs are not expanded.
XOtherwise, tabs are expanded into spaces, and
X.I tabwidth
Xgives the spacing between tab columns.
X.PP
X.I Getlic
Xis like
X.IR getlin ,
Xexcept that the final
X.I comment
Xargument is taken to be a character indicating the start of a
Xcomment that continues until the end of a line.
X.I Getlic
Xstrips comments.
XIt then strips any spaces or tabs at the ends of lines.
XIt does not return blank lines.
X.SH ERRORS
X.I Getlic
Xand
X.I getlin
Xcheck for several errors.
XIn each case,
X.I malf1
Xis called to print an appropriate error message and exit.
XThe file name
X.I filename
Xis included in the error messages.
XThe following errors are checked:
X.IP -
XThe input line would overflow the buffer, whose size is given by
X.I bufsize.
X.IP -
XRead error.
X.IP -
XEnd of file in the middle of a line.
XThat is, the file is not empty, and the last character is not a newline.
X.IP -
XNUL in file.
X.SH RETURNS
XOn success,
X.I getlic
Xand
X.I getlin
Xreturn a pointer to the NUL terminator of the line read into
X.I linebuf.
XOn normal end of file,
Xthey return NULBSTR.
XThey do not return on error.
X.SH EXAMPLE
XTo copy standard input to standard output and expand tabs into spaces:
X.nf
X   unsigned     ln = 0;
X   static byteT l[1024];
X
X   while (NULBSTR != getlin (l, 1024, stdin, "Standard Input", &ln, 8))
X      (void) puts (l);
X.fi
X.SH "SEE ALSO"
X.IR intro (3S),
X.IR malf "(3 -lhoward)."
X.SH BUGS
XOverflow of the line number is not checked.
X.SH LICENSE
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License version 1,
Xas published by the Free Software Foundation.
X.PP
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License for more details.
X.PP
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X.SH AUTHOR
XHoward Gayle,
XTN/ETX/T/BG,
XEricsson Telecom AB,
XS-126 25 Stockholm,
XSweden,
Xhoward@ericsson.se,
Xuunet!ericsson.se!howard,
XPhone: +46 8 719 5565,
XFAX: +46 8 719 9598,
XTelex: 14910 ERIC S
END_OF_FILE
if test 3505 -ne `wc -c <'getlin.3'`; then
    echo shar: \"'getlin.3'\" unpacked with wrong size!
fi
# end of 'getlin.3'
fi
if test -f 'getpwf.3' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'getpwf.3'\"
else
echo shar: Extracting \"'getpwf.3'\" \(2847 characters\)
sed "s/^X//" >'getpwf.3' <<'END_OF_FILE'
X.\" $Header: getpwf.3,v 1.2 89/08/21 08:43:59 howard Exp $
X.TH GETPWF "3 -lhoward" "$Revision: 1.2 $" "Howard\'s C library" "Howard\'s C library"
X.SH NAME
Xgetpwf \- copy full name of user from password file entry
X.SH SYNOPSIS
X.nf
X.BR "#include <" stdio.h ">"
X.BR "#include <" pwd.h ">"
X.BR "#include <" howard/port.h ">"
X.BR "#include <" howard/malf.h ">"
X.fi
X.LP
XbStrT getpwf (
X.IR passwdPtr ,
X.IR buffer )
X.nf
X.BI "struct passwd *" passwdPtr;
X.RI "bStrT " buffer ;
X.fi
X.SH COPYRIGHT
XCopyright \(co 1989 Howard Lee Gayle
X.SH DESCRIPTION
X.I passwdPtr
Xpoints to a password file entry for a user.
X.I getpwf
Xcopies the user's full (real) name into the area to which
X.I buffer
Xpoints.
XIt does this in the face of BSD asterisk, ampersand, and comma kludges.
X.SH RETURNS
XOn success, a pointer to the NUL in
X.I buffer
Xat the end of the copied full name.
XNULL if the full name is empty.
X.SH EXAMPLE
XThe password entry
X.nf
X   howard::159:13:*& Gayle,TN 15028,95565,:/u5/howard:/bin/csh
X.fi
Xresults in "Howard Gayle" in
X.IR buffer .
X.SH "SEE ALSO"
X.IR getpwent (3),
X.IR userfn "(3 \-lhoward)."
X.SH BUGS
XThe BSD asterisk convention is a kludge.
XIt is a convention for password aging.
XAn asterisk at the beginning of the GECOS field is ignored by
Xall software except
X.IR passwd (1),
Xwhich removes it when the password is changed.
XBy periodically setting an asterisk on all password entries, it
Xis possible to see which users have not changed their passwords
Xwithin a given time.
X.PP
XThe BSD ampersand convention is a kludge.
XAn ampersand in the GECOS field expands into a capitalized copy
Xof the login name.
XUsers whose login names are one of their real names can thus
Xhave slightly shorter password entries.
XBig deal!
X.PP
XThe BSD comma convention is a kludge.
XBSD treats the GECOS field as a comma-separated list of
Xsubfields: full name, room number, office phone, home phone.
XThese additional data should go somewhere else.
XThis kludge eliminates full names with commas,
X.I e.g.
XHenry Ford, Jr.
XThis is probably why he never had a UNIX login.
X.SH LICENSE
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License version 1,
Xas published by the Free Software Foundation.
X.PP
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License for more details.
X.PP
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X.SH AUTHOR
XHoward Gayle,
XTN/ETX/T/BG,
XEricsson Telecom AB,
XS-126 25 Stockholm,
XSweden,
Xhoward@ericsson.se,
Xuunet!ericsson.se!howard,
XPhone: +46 8 719 5565,
XFAX: +46 8 719 9598,
XTelex: 14910 ERIC S
END_OF_FILE
if test 2847 -ne `wc -c <'getpwf.3'`; then
    echo shar: \"'getpwf.3'\" unpacked with wrong size!
fi
# end of 'getpwf.3'
fi
if test -f 'getpwf.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'getpwf.c'\"
else
echo shar: Extracting \"'getpwf.c'\" \(3428 characters\)
sed "s/^X//" >'getpwf.c' <<'END_OF_FILE'
X/*
X * getpwf - copy full name of user from password file entry
X */
X
X#ifndef lint
Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
X#endif lint
X
X/*
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License version 1,
X * as published by the Free Software Foundation.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
X#include <stdio.h>
X#include <howard/port.h>
X#include <howard/version.h>
X
XMODVER ("@(#)$Header: getpwf.c,v 1.2 89/08/20 11:05:20 howard Exp $");
X
X#include <ctype.h>
X#include <pwd.h>
X#include <howard/malf.h>
X#include <howard/registers.i>
X
XPUBLIC bStrT getpwf (pwp, fnb)
XR3 struct passwd *pwp; /* Points to password entry.*/
XR4 bStrT          fnb; /* Store full name here.*/
X
X
X/* Function:
X *    
X * Algorithm:
X *    Copy byte-by-byte.  Skip *. Expand &.
X * Returns:
X *    Pointer to EOS terminator in fnb[].
X * Notes:
X *    1) In 4.3BSD, and perhaps other systems, an ampersand (&) in the
X *       GECOS field means the capitalized login name.  When the login
X *       name is the same as the user's first or last name, this makes
X *       the password entry slightly shorter.
X *    2) Some systems treat the GECOS field as many comma-separated fields.
X *       The full name comes first.
X *    3) Some systems use an asterisk (*) in the beginning of the GECOS
X *       field for password aging.  The passwd command removes the *
X *       when changing passwords.  So, to enforce e.g. yearly password
X *       changes, you put a * into everyone's GECOS field at the beginning
X *       of the year, and users who still have a * at the end of the year
X *       are reminded to change their passwords.  Everything else ignores
X *       the *.
X */
X{
XR1 bStrT  p;  /* Steps through GECOS field.*/
XR5 bStrT  p1; /* Steps through login name.*/
XR2 bStrT  p2; /* Steps through fnb[].*/
XR6 rcharT b;  /* First byte of login name.*/
X
Xif (((struct passwd *) NULL) == pwp) malf1 ("getpwf: no password pointer");
Xif (NULBSTR == fnb)                  malf1 ("getpwf: no buffer");
Xp = (bStrT) pwp->pw_gecos;
Xif (NULBSTR == p) return (p);
Xif ('*' == B(*p)) ++p;
Xfor (p2 = fnb; (EOS != B(*p)) && (',' != B(*p)); ++p)
X   {
X   if ('&' != B(*p))
X      *p2++ = B(*p);
X   else
X      {
X      p1 = (bStrT) pwp->pw_name;
X      b = B(*p1);
X      if (isascii (b) && islower (b)) b = toupper (b);
X      *p2++ = b;
X      for (++p1; EOS != B(*p1); ++p1)
X         *p2++ = B(*p1);
X      }
X   }
Xif (p2 == fnb) return (NULBSTR);
X*p2 = EOS;
Xreturn (p2);
X}
X
X#ifdef TEST
X#include <howard/usage.h>
X
XMAINVER ("@(#)$Header: getpwf.c,v 1.2 89/08/20 11:05:20 howard Exp $");
XUSAGE ("login-name");
X
X#include <howard/malf.h>
X
XPUBLIC int main (argc, argv)
Xint    argc; /* Number of arguments.*/
XbStrT *argv; /* Points to array of argument strings.*/
X{
XbyteT fnb[1024]; /* Full name buffer.*/
X
Xif (2 != argc) usage();
X(void) getpwf (getpwnam ((cStrT) argv[1]), fnb);
XPUTS (fnb);
Xmfflush (stdout, S("Standard Output"));
Xexit (SUCCESS);
X
X#ifdef lint
Xreturn (SUCCESS);
X#endif
X}
X#endif
END_OF_FILE
if test 3428 -ne `wc -c <'getpwf.c'`; then
    echo shar: \"'getpwf.c'\" unpacked with wrong size!
fi
# end of 'getpwf.c'
fi
if test -f 'ma2u.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ma2u.c'\"
else
echo shar: Extracting \"'ma2u.c'\" \(3073 characters\)
sed "s/^X//" >'ma2u.c' <<'END_OF_FILE'
X/*
X * ma2u - convert Ada-syntax integer literal to unsigned, handle errors
X */
X
X#ifndef lint
Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
X#endif lint
X
X/*
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License version 1,
X * as published by the Free Software Foundation.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
X#include <stdio.h>
X#include <howard/port.h>
X#include <howard/version.h>
X
XMODVER ("@(#)$Header: ma2u.c,v 1.4 89/08/12 09:37:32 howard Exp $");
X
X#include <errno.h>
X#include <limits.h>
X#include <string.h>
X#include <howard/a2.h>
X#include <howard/malf.h>
X#include <howard/registers.i>
X
XPUBLIC unsigned ma2u (str, lim, synok, fn, end)
X   bStrT  str;   /* Input string.*/
X   bStrT  lim;   /* Don't pass this.*/
X   boolT  synok; /* Accept non-fatal syntax errors.*/
X   bStrT  fn;    /* Field name, for error messages.*/
XR2 bStrT *end;   /* End pointer stored here.*/
X
X/* Function:
X *    
X * Algorithm:
X *    Call a2u() then switch on return code.
X * Returns:
X *    
X * Notes:
X *    
X */
X{
X   bStrT    ep; /* a2u() stores pointer to end of string here.*/
X   unsigned u;  /* a2u() stores its result here.*/
XR3 int      p1; /* Precision for printing str (up to syntax error).*/
XR4 int      p2; /* Precision for printing str (after syntax error).*/
XR1 int      s;  /* Return code.*/
X
Xs = a2u (str, lim, synok, &u, &ep);
Xswitch (s)
X   {
X   case SUCCESS:
X      break;
X   case EDOM:
X      p1 = ep - str;
X      p2 = ((NULBSTR == lim) ? strlen (str) : lim - str) - p1;
X      malf1 ("%s [%.*s|%.*s]: syntax error", fn, p1, str, p2, ep);
X      break;
X   case ERANGE:
X      p1 = ((NULBSTR == lim) ? INT_MAX : lim - str);
X      malf1 ("%s [%.*s] not in range [0, %u]", fn, p1, str, UINT_MAX);
X      break;
X   case EINVAL:
X      if (NULBSTR == str) malf1 ("ma2u: null string argument");
X      /* Falls through.*/
X   default:
X      malf1 ("ma2u: impossible error %d", s);
X   }
Xif (((bStrT *) NULL) != end) *end = ep;
Xreturn (u);
X}
X
X#ifdef TEST
X#include <howard/usage.h>
X
XMAINVER ("@(#)$Header: ma2u.c,v 1.4 89/08/12 09:37:32 howard Exp $");
XUSAGE ("integer-numeric-literal [limit]");
X
XPUBLIC int main (argc, argv)
Xint    argc; /* Number of arguments.*/
XbStrT *argv; /* Points to array of argument strings.*/
X{
XbStrT end; /* Points to end of string.*/
Xunsigned u; /* Returned by ma2u().*/
X
Xif (argc < 2) usage();
Xu = ma2u (argv[1], (2 == argc) ? NULBSTR : &argv[1][atoi (argv[2])], FALSE,
X          S("integer-numeric-literal"), &end);
XPRINTF ("8#%o#\t10#%u#\t16#%X#\t%s\n", u, u, u, end);
Xmfflush (stdout, "Standard Output");
Xexit (SUCCESS);
X
X#ifdef lint
Xreturn (SUCCESS);
X#endif
X}
X#endif
END_OF_FILE
if test 3073 -ne `wc -c <'ma2u.c'`; then
    echo shar: \"'ma2u.c'\" unpacked with wrong size!
fi
# end of 'ma2u.c'
fi
if test -f 'ma2ul.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ma2ul.c'\"
else
echo shar: Extracting \"'ma2ul.c'\" \(3081 characters\)
sed "s/^X//" >'ma2ul.c' <<'END_OF_FILE'
X/*
X * ma2ul - convert Ada-syntax integer literal to long unsigned, handle errors
X */
X
X#ifndef lint
Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
X#endif lint
X
X/*
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License version 1,
X * as published by the Free Software Foundation.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
X#include <stdio.h>
X#include <howard/port.h>
X#include <howard/version.h>
X
XMODVER ("@(#)$Header: ma2ul.c,v 1.3 89/08/12 09:56:17 howard Exp $");
X
X#include <errno.h>
X#include <limits.h>
X#include <string.h>
X#include <howard/a2.h>
X#include <howard/malf.h>
X#include <howard/registers.i>
X
XPUBLIC ulongT ma2ul (str, lim, synok, fn, end)
X   bStrT  str;   /* Input string.*/
X   bStrT  lim;   /* Don't pass this.*/
X   boolT  synok; /* Accept non-fatal syntax errors.*/
X   bStrT  fn;    /* Field name, for error messages.*/
XR2 bStrT *end;   /* End pointer stored here.*/
X
X/* Function:
X *    
X * Algorithm:
X *    Call a2ul() then switch on return code.
X * Returns:
X *    
X * Notes:
X *    
X */
X{
X   bStrT  ep; /* a2ul() stores pointer to end of string here.*/
X   ulongT u;  /* a2ul() stores its result here.*/
XR3 int    p1; /* Precision for printing str (up to syntax error).*/
XR4 int    p2; /* Precision for printing str (after syntax error).*/
XR1 int    s;  /* Return code.*/
X
Xs = a2ul (str, lim, synok, &u, &ep);
Xswitch (s)
X   {
X   case SUCCESS:
X      break;
X   case EDOM:
X      p1 = ep - str;
X      p2 = ((NULBSTR == lim) ? strlen (str) : lim - str) - p1;
X      malf1 ("%s [%.*s|%.*s]: syntax error", fn, p1, str, p2, ep);
X      break;
X   case ERANGE:
X      p1 = ((NULBSTR == lim) ? INT_MAX : lim - str);
X      malf1 ("%s [%.*s] not in range [0, %lu]", fn, p1, str, ULONG_MAX);
X      break;
X   case EINVAL:
X      if (NULBSTR == str) malf1 ("ma2ul: null string argument");
X      /* Falls through.*/
X   default:
X      malf1 ("ma2ul: impossible error %d", s);
X   }
Xif (((bStrT *) NULL) != end) *end = ep;
Xreturn (u);
X}
X
X#ifdef TEST
X#include <howard/usage.h>
X
XMAINVER ("@(#)$Header: ma2ul.c,v 1.3 89/08/12 09:56:17 howard Exp $");
XUSAGE ("integer-numeric-literal [limit]");
X
XPUBLIC int main (argc, argv)
Xint    argc; /* Number of arguments.*/
XbStrT *argv; /* Points to array of argument strings.*/
X{
XbStrT end; /* Points to end of string.*/
XulongT u; /* Returned by ma2ul().*/
X
Xif (argc < 2) usage();
Xu = ma2ul (argv[1], (2 == argc) ? NULBSTR : &argv[1][atoi (argv[2])], FALSE,
X          S("integer-numeric-literal"), &end);
XPRINTF ("8#%lo#\t10#%lu#\t16#%lX#\t%s\n", u, u, u, end);
Xmfflush (stdout, "Standard Output");
Xexit (SUCCESS);
X
X#ifdef lint
Xreturn (SUCCESS);
X#endif
X}
X#endif
END_OF_FILE
if test 3081 -ne `wc -c <'ma2ul.c'`; then
    echo shar: \"'ma2ul.c'\" unpacked with wrong size!
fi
# end of 'ma2ul.c'
fi
if test -f 'malf.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'malf.c'\"
else
echo shar: Extracting \"'malf.c'\" \(3238 characters\)
sed "s/^X//" >'malf.c' <<'END_OF_FILE'
X/*
X * malf - system error handler
X */
X
X#ifndef lint
Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
X#endif lint
X
X/*
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License version 1,
X * as published by the Free Software Foundation.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
X#include <stdio.h>
X#include <howard/port.h>
X#include <howard/version.h>
X
XMODVER ("@(#)$Header: malf.c,v 1.10 89/08/21 17:50:36 howard Exp $");
X
X#include <howard/registers.i>
X#include <howard/malf.h>
X
XPUBLIC boolT _debug = FALSE;
X
X#ifdef NOVPRINTF
X/*VARARGS2*/
XPUBLIC void malf (x, a, b, c, d, e, f)
Xint   x; /* Exit code (0 = no exit).*/
XcStrT a; /* Format string.*/
X#else  NOVPRINTF
X#include <varargs.h>
X
X/*VARARGS0*/
XPUBLIC void malf (va_alist)
Xva_dcl
X#endif NOVPRINTF
X
X/* Function:
X *    Write error message on standard error and (perhaps) exit.
X */
X{
Xextern bStrT   _progn;        /* Version string.*/
Xextern int     errno;         /* See intro(2).*/
Xextern int     sys_nerr;      /* Maximum value of errno for which a
X			       * text entry exists.*/
Xextern cStrT   sys_errlist[]; /* Array of pointers to system error
X			       * text, indexed by errno.*/
Xextern cStrT   ctime();       /* (3).*/
Xextern long    time();        /* (3C).*/
XR1     int     se = errno;    /* Save errno.*/
X       long    ut;            /* Current system time.*/
X#ifndef NOVPRINTF
X       va_list args;
XR2     int     x;             /* Exit code (0 = no exit).*/
XR3     cStrT   a;             /* Format string.*/
X
Xva_start (args);
Xx = va_arg (args, int);
Xa = va_arg (args, cStrT);
X#endif NOVPRINTF
X
XFFLUSH (stdout);
XFPUTS ((0 == x) ? "\nWarning" : "\nError", stderr);
Xif (isatty (fileno (stderr)))
X   {
X   FPUTS (": ", stderr);
X   putspn();
X   }
Xelse
X   {
X   ut = time ((long *) NULL);
X   FPRINTF (stderr, " message at %s", ctime (&ut));
X   if (NULBSTR != _progn) FPRINTF (stderr, "   from: %s\n   ", _progn);
X   }
X
X#ifdef NOVPRINTF
XFPRINTF (stderr, a, b, c, d, e, f);
X#else  NOVPRINTF
X(void) vfprintf (stderr, a, args);
Xva_end (args);
X#endif NOVPRINTF
X
XPUTC ('\n', stderr);
Xif (0 != se)
X   {
X   FPRINTF (stderr, "   System message %d", se);
X   if ((0 < se) && (se <= sys_nerr)) FPRINTF (stderr, ": %s", sys_errlist[se]);
X   PUTC ('\n', stderr);
X   }
XFFLUSH (stderr);
Xif (0 != x)
X   {
X   if (_debug) abort();
X   exit (x);
X   }
Xerrno = 0;
X}
X
X#ifdef TEST
X#include <howard/usage.h>
X
XMAINVER ("@(#)$Header: malf.c,v 1.10 89/08/21 17:50:36 howard Exp $");
XUSAGE ("");
X
XPUBLIC int main (argc, argv)
Xint    argc; /* Number of arguments.*/
XbStrT *argv; /* Points to array of argument strings.*/
X{
Xextern int errno;
Xextern int sys_nerr;
X
Xerrno = 1;
Xmalf (0, "%c %s %d %ld %f", '1', "2", 3, 4L, 5.0);
Xerrno = 1 + sys_nerr;
X_debug = TRUE;
Xmalf (127, "%c %s %d %ld %f", '6', "7", 8, 9L, 10.0);
X}
X#endif
END_OF_FILE
if test 3238 -ne `wc -c <'malf.c'`; then
    echo shar: \"'malf.c'\" unpacked with wrong size!
fi
# end of 'malf.c'
fi
if test -f 'mkLibcLims.b' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mkLibcLims.b'\"
else
echo shar: Extracting \"'mkLibcLims.b'\" \(3641 characters\)
sed "s/^X//" >'mkLibcLims.b' <<'END_OF_FILE'
X  
X# mkLibcLims - make the libc-lims.i include file for this system
X#
X# $Header: mkLibcLims.b,v 1.8 89/09/21 19:22:37 howard Exp $
X#
X# Copyright 1989 Howard Lee Gayle
X# This file is written in the ISO 8859/1 character set.
X#
X# This program is free software; you can redistribute it and/or modify
X# it under the terms of the GNU General Public License version 1,
X# as published by the Free Software Foundation.
X#
X# This program is distributed in the hope that it will be useful,
X# but WITHOUT ANY WARRANTY; without even the implied warranty of
X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X# GNU General Public License for more details.
X#
X# You should have received a copy of the GNU General Public License
X# along with this program; if not, write to the Free Software
X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X#
X# Shell variables:
X# c - full path to libc.a
X# t - temporary file
X# u - usage string
X
XCMDNAME=mkLibcLims
Xexport CMDNAME
Xu='Usage: $CMDNAME libc-lims.i'
Xif [ $# -ne 1 ]
Xthen
X   echo "$u" 1>&2
X   exit 1
Xfi
Xif [ -r /lib/libc.a ]
Xthen
X   c=/lib/libc.a
Xelif [ -r /usr/lib/libc.a ]
Xthen
X   c=/usr/lib/libc.a
Xelse
X   echo 'mkLibcLims: can not find libc.a' 1>&2
X   exit 1
Xfi
Xt=/tmp/libc$$
Xnm $c 2>/dev/null | sed -n -e 's/^.* T _//p' -e 's/^.* T //p' > $t
Xif grep '^printf$' $t > /dev/null 2>&1
Xthen
X   :
Xelse
X   nm $c 2>/dev/null | sed -n -e 's/^.* D _//p' -e 's/^.* D //p' > $t
X   if grep '^printf$' $t > /dev/null 2>&1
X   then
X      :
X   else
X      ar t $c | sed -e 's/\.o$//' > $f
X      if grep '^printf$' $t > /dev/null 2>&1
X      then
X         :
X      else
X         echo "mkLibcLims: can not list contents of $c" 1>&2
X         exit 1
X      fi
X   fi
Xfi
Xecho '/*' > $1
Xecho ' * libc-lims.i - C library limitations file' >> $1
Xecho ' *' >> $1
Xecho ' * This file was generated automatically by:' >> $1
Xecho ' *    $Header: mkLibcLims.b,v 1.8 89/09/21 19:22:37 howard Exp $' >> $1
Xecho ' */' >> $1
Xecho '' >> $1
X
Xif grep '^drand48$' $t > /dev/null 2>&1
Xthen
X   echo '/*#define NODRAND48 1 /* Comment in if no drand48() function.*/' >> $1
Xelse
X   echo   '#define NODRAND48 1 /* Comment in if no drand48() function.*/' >> $1
Xfi
X
Xif grep '^getopt$' $t > /dev/null 2>&1
Xthen
X   echo '/*#define NOGETOPT 1 /* Comment in if no getopt() function.*/' >> $1
Xelse
X   echo   '#define NOGETOPT 1 /* Comment in if no getopt() function.*/' >> $1
Xfi
X
Xif grep '^memcmp$' $t > /dev/null 2>&1
Xthen
X   echo '/*#define NOMEMCMP 1 /* Comment in if no memcmp() function.*/' >> $1
Xelse
X   echo   '#define NOMEMCMP 1 /* Comment in if no memcmp() function.*/' >> $1
Xfi
X
Xif grep '^random$' $t > /dev/null 2>&1
Xthen
X   echo '/*#define NORANDOM 1 /* Comment in if no random() function.*/' >> $1
Xelse
X   echo   '#define NORANDOM 1 /* Comment in if no random() function.*/' >> $1
Xfi
X
Xif grep '^rename$' $t > /dev/null 2>&1
Xthen
X   echo '/*#define NORENAME 1 /* Comment in if no rename() function.*/' >> $1
Xelse
X   echo   '#define NORENAME 1 /* Comment in if no rename() function.*/' >> $1
Xfi
X
Xif grep '^strchr$' $t > /dev/null 2>&1
Xthen
X   echo '/*#define NOSTRCHR 1 /* Comment in if no strchr() function.*/' >> $1
Xelse
X   echo   '#define NOSTRCHR 1 /* Comment in if no strchr() function.*/' >> $1
Xfi
X
Xif grep '^strspn$' $t > /dev/null 2>&1
Xthen
X   echo '/*#define NOSTRSPN 1 /* Comment in if no strspn() function.*/' >> $1
Xelse
X   echo   '#define NOSTRSPN 1 /* Comment in if no strspn() function.*/' >> $1
Xfi
X
Xif grep '^vprintf$' $t > /dev/null 2>&1
Xthen
X   echo '/*#define NOVPRINTF 1 /* Comment in if no vprintf() function.*/' >> $1
Xelse
X   echo   '#define NOVPRINTF 1 /* Comment in if no vprintf() function.*/' >> $1
Xfi
Xrm $t
END_OF_FILE
if test 3641 -ne `wc -c <'mkLibcLims.b'`; then
    echo shar: \"'mkLibcLims.b'\" unpacked with wrong size!
fi
# end of 'mkLibcLims.b'
fi
if test -f 'msgfn.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'msgfn.c'\"
else
echo shar: Extracting \"'msgfn.c'\" \(3515 characters\)
sed "s/^X//" >'msgfn.c' <<'END_OF_FILE'
X/*
X * msgfn - Extract full name from mail message or news article header
X */
X
X#ifndef lint
Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
X#endif lint
X
X/*
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License version 1,
X * as published by the Free Software Foundation.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
X#include <stdio.h>
X#include <howard/port.h>
X#include <howard/version.h>
X
XMODVER ("@(#)$Header: msgfn.c,v 1.2 89/08/19 10:19:10 howard Exp $");
X
X#include <string.h>
X#include <howard/malf.h>
X#include <howard/registers.i>
X
XPUBLIC boolT msgfn (s, b)
XR3 bStrT s; /* String containing an address field.*/
XR4 bStrT b; /* Buffer in which to store result.*/
X
X/* Function:
X *    
X * Algorithm:
X *    If there's something in double quotes, copy what's in the leftmost pair.
X *    If there's something in parentheses, copy what's in the leftmost pair.
X *    If there's something in angle brackets, copy everything else,
X *    except leading and trailing spaces.
X * Returns:
X *    TRUE iff a full name was copied.
X * Notes:
X *    1) What's in double quotes isn't always a full name, but it's a good bet.
X */
X{
XR1 bStrT p1; /* Points to first delimiter.*/
XR2 bStrT p2; /* Points to second delimiter.*/
X
Xif (NULBSTR == s) malf1 ("msgfn: no input");
Xif (NULBSTR == b) malf1 ("msgfn: no output");
Xp1 = bStrChr (s, '"');
Xif (NULBSTR != p1)
X   {
X   ++p1;
X   p2 = bStrChr (p1, '"');
X   if ((NULBSTR != p2) && (p1 != p2))
X      {
X      STRNCPY ((cStrT) b, (cStrT) p1, p2 - p1);
X      return (TRUE);
X      }
X   }
Xp1 = bStrChr (s, '(');
Xif (NULBSTR != p1)
X   {
X   ++p1;
X   p2 = bStrChr (p1, ')');
X   if ((NULBSTR != p2) && (p1 != p2))
X      {
X      STRNCPY ((cStrT) b, (cStrT) p1, p2 - p1);
X      return (TRUE);
X      }
X   }
Xp1 = bStrChr (s, '<');
Xif (NULBSTR != p1)
X   {
X   p2 = bStrChr (p1 + 1, '>');
X   if ((NULBSTR != p2) && ((p1 + 1) != p2))
X      {
X      while (' ' == B(*s))
X         ++s;
X      if (s != p1) STRNCPY ((cStrT) b, (cStrT) s, p1 - s);
X      p1 = p2 + 1;
X      for (p2 = strend (p1); ' ' == B(p2[-1]); --p2)
X         ;
X      if (p1 != p2) STRNCAT ((cStrT) b, (cStrT) p1, p2 - p1);
X      return (TRUE);
X      }
X   }
Xreturn (FALSE);
X}
X
X#ifdef TEST
X#include <howard/usage.h>
X
XMAINVER ("@(#)$Header: msgfn.c,v 1.2 89/08/19 10:19:10 howard Exp $");
XUSAGE ("");
X
X
XPRIVATE void t (n, s, xr, xb)
Xint n; /* Test number.*/
XbStrT s; /* Test string.*/
XboolT xr; /* Expected return.*/
XbStrT xb; /* Expected stored result.*/
X{
XbyteT b[1024]; /* Store result here.*/
X
Xif (xr != msgfn (s, b))
X   PRINTF ("%d: rc %d expected\n", n, xr);
Xelse if (xr && !bStrEQ (b, xb))
X   PRINTF ("%d: result %s expected %s\n", n, b, xb);
X}
X
XPUBLIC int main ()
X{
Xt(__LINE__, S("\"Howard Gayle\"@ericsson.se"), TRUE, S("Howard Gayle"));
Xt(__LINE__, S("howard@ericsson.se (Howard Gayle)"), TRUE, S("Howard Gayle"));
Xt(__LINE__, S("Howard Gayle<howard@ericsson.se>"), TRUE, S("Howard Gayle"));
Xt(__LINE__, S("howard@ericsson.se"), FALSE, NULBSTR);
Xmfflush (stdout, S("Standard Output"));
Xexit (SUCCESS);
X
X#ifdef lint
Xreturn (SUCCESS);
X#endif
X}
X#endif
END_OF_FILE
if test 3515 -ne `wc -c <'msgfn.c'`; then
    echo shar: \"'msgfn.c'\" unpacked with wrong size!
fi
# end of 'msgfn.c'
fi
if test -f 'smp.3' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'smp.3'\"
else
echo shar: Extracting \"'smp.3'\" \(3670 characters\)
sed "s/^X//" >'smp.3' <<'END_OF_FILE'
X.\" $Header: smp.3,v 1.3 89/08/15 14:53:10 howard Exp $
X.TH SMP "3 -lhoward" "$Revision: 1.3 $" "Howard\'s C library" "Howard\'s C library"
X.SH NAME
Xa2smp, mk-smp, smp2l, smp2u, smp2ul, smpdig, smpdtl \- simple multiple precision system
X.SH SYNOPSIS
X.B mk-smp
X.LP
X.nf
X.BR "#include <" stdio.h ">"
X.BR "#include <" howard/port.h ">"
X.BR "#include <" howard/simultipre.i ">"
X.BR "#include <" howard/smp.h ">"
X.fi
X.LP
X.BR "int " "a2smp ("
X.IR string ,
X.IR limit ,
X.IR looseSyntax ,
X.IR resultPointer ,
X.IR endPointer " )"
X.nf
X.RI "bStrT " string ";"
X.RI "bStrT " limit ";"
X.RI "boolT " looseSyntax ";"
X.RI "smpT *" resultPointer;
X.RI "bStrT *" endPointer ;
X.fi
X.LP
X.BR "int " "smp2l ("
X.IR smpPtr ,
X.IR longPtr )
X.nf
X.RI "smpT *" smpPtr ;
X.BI "long *" longPtr;
X.fi
X.LP
X.BR "int " "smp2u ("
X.IR smpPtr ,
X.IR unsignedPtr )
X.nf
X.RI "smpT *" smpPtr ;
X.BI "unsigned *" unsignedPtr;
X.fi
X.LP
X.BR "int " "smp2ul ("
X.IR smpPtr ,
X.IR ulongTPtr )
X.nf
X.RI "smpT *" smpPtr ;
X.RI "ulongT *" ulongTPtr ;
X.fi
X.LP
XboolT smpdig (
X.IR digit ,
X.IR radix ,
X.IR smpPtr )
X.nf
X.BI "int " digit;
X.BI "unsigned " radix;
X.RI "smpT *" smpPtr ;
X.fi
X.LP
X.BR "int " "smpdtl ("
X.IR chr ,
X.IR digitTable )
X.nf
X.RI "rcharT " chr ;
X.RI "bStrT *" digitTable ;
X.fi
X.SH COPYRIGHT
XCopyright \(co 1989 Howard Lee Gayle
X.SH DESCRIPTION
XThese functions provide a very simple multiple precision (SMP)
Xfacility for use in converting string representations of
Xinteger numeric literals to internal representations while
Xchecking for overflow.
XSMPs can represent numbers enough bigger than the biggest
Xinternal representation (typically unsigned long) to detect
Xoverflow.
X.PP
XThe
X.I mk-smp
Xcommand chooses a representation automatically based on the
Xlimits.h include file, and outputs another include file,
Xsimultipre.i, which defines the representation.
X.PP
X.I a2smp
Xconverts Ada-syntax integer numeric literals to simple multiple
Xprecision (SMP) numbers.
XSee
X.IR a2 (3).
X.PP
X.I smp2l
Xtries to convert the simple multiple precision number to which
X.I smpPtr
Xpoints to a long.
XIf
X.I longPtr
Xis not NULL, then the result is stored in the area to which
X.I longPtr
Xpoints.
X.I smp2l
Xreturns 0 on success, EINVAL on invalid arguments, and ERANGE
Xon overflow.
X.I smp2u
Xis the corresponding function for unsigned.
X.I smp2ul
Xis the corresponding function for unsigned long.
X.PP
X.I smpdig
Xperforms the operation
X.nf
X   smp = smp * radix + digit;
X.fi
Xwhere smp is the simple multiple precision number to which
X.I smpPtr
Xpoints.
X.I smpdig
Xreturns TRUE on success and FALSE on overflow.
X.PP
X.I smpdtl
Xsearches a digit table for character
X.IR chr .
XA digit table is an array of strings, where each string
Xcontains all the possible characters representing that digit.
XOn a match,
X.I smpdtl
Xreturns the index in the digit table at which the match occurred;
Xotherwise it returns -1.
X.SH "SEE ALSO"
X.IR a2 "(3 \-lhoward)."
X.SH LICENSE
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License version 1,
Xas published by the Free Software Foundation.
X.PP
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License for more details.
X.PP
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X.SH AUTHOR
XHoward Gayle,
XTN/ETX/T/BG,
XEricsson Telecom AB,
XS-126 25 Stockholm,
XSweden,
Xhoward@ericsson.se,
Xuunet!ericsson.se!howard,
XPhone: +46 8 719 5565,
XFAX: +46 8 719 9598,
XTelex: 14910 ERIC S
END_OF_FILE
if test 3670 -ne `wc -c <'smp.3'`; then
    echo shar: \"'smp.3'\" unpacked with wrong size!
fi
# end of 'smp.3'
fi
if test -f 'smp2l.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'smp2l.c'\"
else
echo shar: Extracting \"'smp2l.c'\" \(3330 characters\)
sed "s/^X//" >'smp2l.c' <<'END_OF_FILE'
X/*
X * smp2l - convert simple multiple precision number to long
X */
X
X#ifndef lint
Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
X#endif lint
X
X/*
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License version 1,
X * as published by the Free Software Foundation.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
X#include <stdio.h>
X#include <howard/port.h>
X#include <howard/version.h>
X
XMODVER ("@(#)$Header: smp2l.c,v 1.9 89/08/14 18:20:04 howard Exp $");
X
X#include <errno.h>
X#include <limits.h>
X#include <howard/registers.i>
X#include <howard/simultipre.i>
X#include <howard/smp.h>
X
XPUBLIC int smp2l (sp, lp)
XR4 smpT *sp; /* Points to SMP.*/
XR5 long *lp; /* Points to where to store result.*/
X
X/* Function:
X *    
X * Algorithm:
X *    Check for max negative number as special case.
X *    Check for overflow.  Or each part of smp into res.
X *    Negate if necessary.
X * Returns:
X *    
X * Notes:
X *    
X */
X{
XR3     long    res;               /* Result.*/
XR1     smpElT *p1;                /* Steps through sp->smp_el[].*/
XR2     smpElT *p2;                /* Most significant element.*/
Xstatic smpT    smpMinL = SMPLMIN; /* LONG_MIN in SMP format.*/
X
Xif (((smpT *) NULL) == sp) return (EINVAL);
Xif (0 == memcmp ((cStrT) sp, (cStrT) &smpMinL, sizeof (smpT)))
X   res = LONG_MIN;
Xelse
X   {
X   p2 = &sp->smp_el[SMPNL - 1];
X   for (p1 = &sp->smp_el[SMPNEL - 1]; p1 != p2;)
X      if (0 != *p1--) return (ERANGE);
X   if (0 != (*p1 >> SMPLHB)) return (ERANGE);
X   for (res = 0L; p1 >= sp->smp_el; --p1)
X      res = (res << SMPEB) | *p1;
X   if (sp->smp_neg) res = -res;
X   }
Xif (((long *) NULL) != lp) *lp = res;
Xreturn (SUCCESS);
X}
X
X#ifdef TEST
X#include <howard/usage.h>
X
XMAINVER ("@(#)$Header: smp2l.c,v 1.9 89/08/14 18:20:04 howard Exp $");
XUSAGE ("");
X
X#include <howard/malf.h>
X
XPRIVATE void t (num, neg, hi, lo, xrc, xres)
Xint num; /* Test number.*/
XboolT neg; /* smp_neg */
XsmpElT hi; /* smp_el[1] */
XsmpElT lo; /* smp_el[0] */
Xint xrc; /* Expected return code.*/
Xlong xres; /* Expected result.*/
X{
Xint rc; /* Return code.*/
Xlong res; /* Result stored here.*/
XsmpT smp; /* SMP argument.*/
X
Xsmp.smp_neg = neg;
Xsmp.smp_el[0] = lo;
Xsmp.smp_el[1] = hi;
Xrc = smp2l (&smp, &res);
Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
Xif ((0 == rc) && (0 == xrc) && (res != xres))
X   PRINTF ("%d: res %lX expected %lX\n", num, res, xres);
X}
X
XPUBLIC int main ()
X{
Xt(__LINE__, 0,      0,      0,      0,            0L);
Xt(__LINE__, 1, 0x8000,      0,      0,(long)LONG_MIN);
Xt(__LINE__, 0, 0x8000,      1, ERANGE,            0L);
Xt(__LINE__, 1, 0x7FFF, 0xFFFF,      0, LONG_MIN + 1L);
Xt(__LINE__, 1,      0,      1,      0,           -1L);
Xt(__LINE__, 0,      0,      1,      0,            1L);
Xt(__LINE__, 0, 0x7FFF, 0xFFFF,      0,(long)LONG_MAX);
X
Xmfflush (stdout, "Standard Output");
Xexit (SUCCESS);
X
X#ifdef lint
Xreturn (SUCCESS);
X#endif
X}
X#endif
END_OF_FILE
if test 3330 -ne `wc -c <'smp2l.c'`; then
    echo shar: \"'smp2l.c'\" unpacked with wrong size!
fi
# end of 'smp2l.c'
fi
if test -f 'smp2u.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'smp2u.c'\"
else
echo shar: Extracting \"'smp2u.c'\" \(3463 characters\)
sed "s/^X//" >'smp2u.c' <<'END_OF_FILE'
X/*
X * smp2ul - convert simple multiple precision number to unsigned
X */
X
X#ifndef lint
Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
X#endif lint
X
X/*
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License version 1,
X * as published by the Free Software Foundation.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
X#include <stdio.h>
X#include <howard/port.h>
X#include <howard/version.h>
X
XMODVER ("@(#)$Header: smp2u.c,v 1.2 89/08/14 18:29:32 howard Exp $");
X
X#include <errno.h>
X#include <limits.h>
X#include <howard/registers.i>
X#include <howard/simultipre.i>
X#include <howard/smp.h>
X
XPUBLIC int smp2u (sp, lp)
XR1 smpT     *sp; /* Points to SMP.*/
XR5 unsigned *lp; /* Points to where to store result.*/
X
X/* Function:
X *    
X * Algorithm:
X *    Step downward through higher order SMP elements that ought to
X *    be zero, and make sure they are.  Make sure high order bits in
X *    the highest order element are also zero.  Or each element into
X *    the result.  Check for a negative result.  Store the result.
X * Returns:
X *    
X * Notes:
X *    
X */
X{
XR4 unsigned res = 0; /* Result.*/
XR2 smpElT  *p1;      /* Steps through sp->smp_el[].*/
XR3 smpElT  *p2;      /* Highest order smp_el used.*/
X
Xif (((smpT *) NULL) == sp) return (EINVAL);
Xp2 = &sp->smp_el[SMPNU - 1];
Xfor (p1 = &sp->smp_el[SMPNEL - 1]; p1 != p2; --p1)
X   if (0 != *p1) return (ERANGE);
Xif (0 != (*p1 >> SMPUHB)) return (ERANGE);
Xwhile (p1 >= sp->smp_el)
X   res = (res << SMPEB) | *p1--;
Xif (sp->smp_neg && (0 != res)) return (ERANGE);
Xif (((unsigned *) NULL) != lp) *lp = res;
Xreturn (SUCCESS);
X}
X
X#ifdef TEST
X#include <howard/usage.h>
X
XMAINVER ("@(#)$Header: smp2u.c,v 1.2 89/08/14 18:29:32 howard Exp $");
XUSAGE ("");
X
X#include <howard/malf.h>
X
XPRIVATE void t (num, neg, hi, lo, xrc, xres)
Xint   num; /* Test number.*/
XboolT neg; /* smp_neg */
XsmpElT hi; /* smp_el[1] */
XsmpElT lo; /* smp_el[0] */
Xint   xrc; /* Expected return code.*/
Xunsigned xres; /* Expected result.*/
X{
Xint rc; /* Return code.*/
Xunsigned res; /* Result stored here.*/
XsmpT smp; /* SMP argument.*/
X
Xsmp.smp_neg = neg;
Xsmp.smp_el[0] = lo;
Xsmp.smp_el[1] = hi;
Xrc = smp2u (&smp, &res);
Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
Xif ((0 == rc) && (0 == xrc) && (res != xres))
X   PRINTF ("%d: res %X expected %X\n", num, res, xres);
X}
X
XPUBLIC int main ()
X{
X/* num    sgn   hi      lo      rc         res   */
Xt(__LINE__, 0,      0,      0,      0, (unsigned)           0);
Xt(__LINE__, 1,      0,      0,      0, (unsigned)           0);
Xt(__LINE__, 0,      0,      1,      0, (unsigned)           1);
Xt(__LINE__, 0, 0x7FFF, 0xFFFF,      0, (unsigned)  0x7FFFFFFF);
Xt(__LINE__, 0, 0x8000,      0,      0, (unsigned)  0x80000000);
Xt(__LINE__, 0, 0xFFFF, 0xFFFF,      0, (unsigned)  0xFFFFFFFF);
Xt(__LINE__, 0,0x10000, 0x0000, ERANGE, (unsigned)           0);
Xt(__LINE__, 1,      0,      1, ERANGE, (unsigned)           0);
X
Xmfflush (stdout, "Standard Output");
Xexit (SUCCESS);
X
X#ifdef lint
Xreturn (SUCCESS);
X#endif
X}
X#endif
END_OF_FILE
if test 3463 -ne `wc -c <'smp2u.c'`; then
    echo shar: \"'smp2u.c'\" unpacked with wrong size!
fi
# end of 'smp2u.c'
fi
if test -f 'smp2ul.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'smp2ul.c'\"
else
echo shar: Extracting \"'smp2ul.c'\" \(3441 characters\)
sed "s/^X//" >'smp2ul.c' <<'END_OF_FILE'
X/*
X * smp2ul - convert simple multiple precision number to unsigned long
X */
X
X#ifndef lint
Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
X#endif lint
X
X/*
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License version 1,
X * as published by the Free Software Foundation.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
X#include <stdio.h>
X#include <howard/port.h>
X#include <howard/version.h>
X
XMODVER ("@(#)$Header: smp2ul.c,v 1.7 89/08/15 11:14:04 howard Exp $");
X
X#include <errno.h>
X#include <limits.h>
X#include <howard/registers.i>
X#include <howard/simultipre.i>
X#include <howard/smp.h>
X
XPUBLIC int smp2ul (sp, lp)
XR1 smpT   *sp; /* Points to SMP.*/
XR5 ulongT *lp; /* Points to where to store result.*/
X
X/* Function:
X *    
X * Algorithm:
X *    Step downward through higher order SMP elements that ought to
X *    be zero, and make sure they are.  Make sure high order bits in
X *    the highest order element are also zero.  Or each element into
X *    the result.  Check for a negative result.  Store the result.
X * Returns:
X *    
X * Notes:
X *    
X */
X{
XR4 ulongT  res = 0; /* Result.*/
XR2 smpElT *p1;      /* Steps through sp->smp_el[].*/
XR3 smpElT *p2;      /* Highest order smp_el used..*/
X
Xif (((smpT *) NULL) == sp) return (EINVAL);
Xp2 = &sp->smp_el[SMPNUL - 1];
Xfor (p1 = &sp->smp_el[SMPNEL - 1]; p1 != p2;)
X   if (0 != *p1--) return (ERANGE);
Xif (0 != (*p1 >> SMPULHB)) return (ERANGE);
Xwhile (p1 >= sp->smp_el)
X   res = (res << SMPEB) | *p1--;
Xif (sp->smp_neg && (0 != res)) return (ERANGE);
Xif (((ulongT *) NULL) != lp) *lp = res;
Xreturn (SUCCESS);
X}
X
X#ifdef TEST
X#include <howard/usage.h>
X
XMAINVER ("@(#)$Header: smp2ul.c,v 1.7 89/08/15 11:14:04 howard Exp $");
XUSAGE ("");
X
X#include <howard/malf.h>
X
XPRIVATE void t (num, neg, hi, lo, xrc, xres)
Xint num; /* Test number.*/
XboolT neg; /* smp_neg */
XsmpElT hi; /* smp_el[1] */
XsmpElT lo; /* smp_el[0] */
Xint xrc; /* Expected return code.*/
XulongT xres; /* Expected result.*/
X{
Xint rc; /* Return code.*/
XulongT res; /* Result stored here.*/
XsmpT smp; /* SMP argument.*/
X
Xsmp.smp_neg = neg;
Xsmp.smp_el[0] = lo;
Xsmp.smp_el[1] = hi;
Xrc = smp2ul (&smp, &res);
Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
Xif ((0 == rc) && (0 == xrc) && (res != xres))
X   PRINTF ("%d: res %lX expected %lX\n", num, res, xres);
X}
X
XPUBLIC int main ()
X{
X/* num    sgn   hi      lo      rc         res   */
Xt(__LINE__, 0,      0,      0,      0, (ulongT)           0);
Xt(__LINE__, 1,      0,      0,      0, (ulongT)           0);
Xt(__LINE__, 0,      0,      1,      0, (ulongT)           1);
Xt(__LINE__, 0, 0x7FFF, 0xFFFF,      0, (ulongT)  0x7FFFFFFF);
Xt(__LINE__, 0, 0x8000,      0,      0, (ulongT)  0x80000000);
Xt(__LINE__, 0, 0xFFFF, 0xFFFF,      0, (ulongT)  0xFFFFFFFF);
Xt(__LINE__, 0,0x10000, 0x0000, ERANGE, (ulongT)           0);
Xt(__LINE__, 1,      0,      1, ERANGE, (ulongT)           0);
X
Xmfflush (stdout, "Standard Output");
Xexit (SUCCESS);
X
X#ifdef lint
Xreturn (SUCCESS);
X#endif
X}
X#endif
END_OF_FILE
if test 3441 -ne `wc -c <'smp2ul.c'`; then
    echo shar: \"'smp2ul.c'\" unpacked with wrong size!
fi
# end of 'smp2ul.c'
fi
echo shar: End of archive 5 \(of 9\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 9 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0