home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: A.Raman@massey.ac.nz ("Anand")
- Subject: v26i035: psimail - UNIX-VMS PSI Mailer, Part02/02
- Message-ID: <1991Nov20.235023.15547@sparky.imd.sterling.com>
- X-Md4-Signature: 9788826c27c485b8e5d8fcfdbdb2c292
- Date: Wed, 20 Nov 1991 23:50:23 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: A.Raman@massey.ac.nz ("Anand")
- Posting-number: Volume 26, Issue 35
- Archive-name: psimail/part02
- Environment: UNIX
-
- #! /bin/sh
- # 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.
- # Contents: psimail/README psimail/debugmsg.c psimail/str.c
- # psimail/str.h
- # Wrapped by kent@sparky on Tue Nov 12 22:43:54 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 2 (of 2)."'
- if test -f 'psimail/README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'psimail/README'\"
- else
- echo shar: Extracting \"'psimail/README'\" \(13111 characters\)
- sed "s/^X//" >'psimail/README' <<'END_OF_FILE'
- X----------------------------------------------------------------------------
- X Copyright (c) 1991 Computing Services, Massey University,
- X Palmerston North, New Zealand
- X All rights reserved.
- X
- X Redistribution and use in source and binary forms, with or without
- X modification, are permitted provided that the following conditions
- X are met:
- X 1. Redistributions of source code must retain the above copyright
- X notice, this list of conditions and the following disclaimer.
- X 2. Redistributions in binary form must reproduce the above copyright
- X notice, this list of conditions and the following disclaimer in the
- X documentation and/or other materials provided with the distribution.
- X 3. All advertising materials mentioning features or use of this software
- X must display the following acknowledgement:
- X This product includes software developed by the Systems Software
- X Support Group, Computing Services, Massey University,
- X Palmerston North, NZ.
- X 4. The name of Massey University may not be used to endorse or promote
- X products derived from this software without specific prior written
- X permission.
- X
- X THIS SOFTWARE IS PROVIDED BY COMPUTING SERVICES, MASSEY UNIVERSITY
- X `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- X TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- X PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MASSEY UNIVERSITY BE
- X LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- X CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- X SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- X INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- X CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- X ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- X POSSIBILITY OF SUCH DAMAGE.
- X
- X----------------------------------------------------------------------------
- X Introduction:
- X ~~~~~~~~~~~~~
- X
- XThis package contains the files necessary to make the two binaries:
- XSendpsimail and Recvpsimail.
- X
- XThese programs enable a UNIX machine to communicate via email with Mail
- Xservers running PSI_MAILSHR. In most situations these are VAX/VMS
- Xmachines. The medium of transfer is x.25 and the protocol used is
- XMAIL-11.
- X
- XThey have specific relevance to the Pyramid implementation of x.25 (1980)
- Xalthough a hack to port on other platforms should not be too difficult.
- XI will be happy to assist in a port to Sunlink x.25 if necessary.
- X
- XAfter unpacking, you should find the following files:
- X
- X1. README
- X2. Makefile
- X3. sendpsimail.c
- X4. recvpsimail.c
- X5. debugmsg.c
- X6. str.c
- X7. str.h
- X
- X`Make' should compile and lint without complaining on a Pyramid. You
- Xmay initially want to run the modules in debug mode for a couple of
- Xdays. To do so, just uncomment the DEBUG definition on the CFLAGS line.
- XIf your /tmp directory is zonked by cron each night, you'd also have to
- Xchange the definition of DEBUGDIR so you don't lose debug data gathered
- Xovernight. Each debug file will have an entire transaction between the
- Xlocal host and the remote PSI site.
- X
- XAlso, you might want to alter the destination and the name of the
- Xmailer. The Sendmail example given later in this document uses the
- Xmailer name `psi', so if you change the mailer name, make sure you
- Xuse that name for the Mailer definition in your sendmail.cf.
- X
- XIf the cpp symbol USER2ALIAS is defined, the mailer will assume that the
- Xmail alias of the user is the same as his/her/its user code. If you
- Xhave a function that does a translation from the usercode to the user's
- Xmail alias link in your own function called user2alias() that includes a
- Xcall to it. Also comment out the USER2ALIAS on the DEFs line so that
- Xthe dummy user2alias() provided will not be used.
- X
- XThe syntax for the user2alias function is:
- X
- Xchar *user2alias(u)
- X
- XIt should return the mail alias for the specified user `u.' At the very
- Xleast, it should return `u' itself, like the dummy one in the mailer
- Xdoes. It should also return `u' if an alias search for the specified
- Xuser failed.
- X
- XCheers!
- X
- X- venkataraman anand, November 1991 (A.Raman@massey.ac.nz)
- X (6300006412::A.Raman)
- X
- X
- X Acknowledgements:
- X ~~~~~~~~~~~~~~~~~
- X
- XPeter Kay of the Computer Science department, Massey University
- Xconceived this project and we chose to design and implement it as a part
- Xof an Honors project in Computer Science 1991. Thanks are due to
- XG.Eustace@massey.ac.nz, (Glen Eustace) for suggestions on improving the
- Xuser interface, bgg@pta.pyramid.com.au (Ben Golding) for helping
- Xidentify a problem with Sendpsimail occasionally dumping core on a
- XSIGPROF signal, K.Spagnolo@massey.ac.nz (Ken Spagnolo) for helpful tips
- Xabout Sendmail and J.Waters@massey.ac.nz (Joyce Waters) for her VMS
- Xaccount that I borrowed to test out intermediate and final stages of
- Xthis project.
- X
- X
- X How Incoming and Outgoing mail are treated:
- X ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- X
- XIncoming PSI-MAIL is received through an x.25 sub address. This was
- Xbecause the Pyramid was found to ignore the user data field of incoming
- Xx.25 call request packets and the conventional method of selecting the
- XPSI-MAIL service is via a special user data field.
- X
- XOutgoing PSI mail is sent by connecting to each of the specified x.25
- Xnodes in sequence and delivering the message to all users on that node
- Xin the same transaction. The way to send mail to a PSI site is to use
- Xan address of the form XXXXXXXX::User@psi-gateway.domain, where XXXXXXXX
- Xis the x.25 address of the node. For example, I can be reached at
- X6300006412::A.Raman@psi-gateway.massey.ac.nz, (It might be cheaper to
- Xreach me at A.Raman@massey.ac.nz, see "Charging Users for PSIMAIL usage")
- X
- XBoth x.25 and Sendmail can be configured differently, however, to receive
- Xand send mail in any other fashion than has been suggested in this
- Xdocument.
- X
- X
- X Recvpsimail and the x.25 configuration:
- X ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- X
- XRecvpsimail is the program that receives PSI mail. If you are running a
- Xlater verison of the x.25 implementation, and it allows selection of
- Xservices based on the user-data field of the call request packet, you
- Xmay choose to configure the x.25 differently. Generally, x25d must be
- Xsetup so that Recvpsimail is activated if an incoming call request
- Xpacket contains the following user data field:
- X
- X{ '\377', '\0', '\0', '\0',
- X 'V', '3', '.', '0',
- X ' ', 'M', 'A', 'I', 'L', '-', '1', '1' }
- X
- XIf you choose to stick to the method of sub-addresses used in here, it
- Xshould still work, but you will have to dedicate an x.25 sub-address
- Xfor the purpose of receiving PSI mail.
- X
- X
- X Example x25 configuration:
- X ~~~~~~~~~~~~~~~~~~~~~~~~~~
- X
- X
- XOn the Pyramid the file /usr/spool/x25/x25d.action needs to be changed.
- XInclude the line:
- X
- XXX 0 0 /usr/x25/x25subXX
- X
- Xwhere XX is the subaddress at which you want to receive PSI-MAIL.
- X
- XYour /usr/x25/x25subXX should probably look like this:
- X
- X> #! /bin/sh
- X> ucb su $USER -c "/usr/local/etc/recvpsimail $* \
- X> 2>/usr/local/etc/recvpsimail.errors"
- X
- X
- X Sendpsimail and the Sendmail configuration:
- X ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- X
- XSendpsimail is the mailer program. Ideally, it is called by Sendmail
- Xwhen Sendmail recognizes an address of the form %s@psi-gateway. Such an
- Xaddress selects the PSI mailer and passes the string defined by %s as a
- Xcommand line argument to it. Sendpsimail is designed to connect to
- Xmultiple nodes in one invocation. But Sendmail can be set up so that
- XSendpsimail is called separately for each destination address.
- X
- XThe first thing that Sendpsimail does upon startup is try to determine
- Xthe username of the caller from the uid of the calling program. In most
- Xinstances when Sendmail runs setuid to caller, the username is resolved
- Xcorrectly. However, the sendername is always reset from the "From: "
- Xline of the mail message. In the rare situation when the mail message
- Xdoes not contain a "From: " line, Sendpsimail would send the message as
- Xthough it originated from the caller of the mailing program. In such a
- Xcase, if Sendmail was not running setuid to caller, the message could be
- Xsent out as `root.' There is a still more important reason to have
- XSendmail running setuid to caller. That will be discussed under the
- Xsection - Charging users for PSIMAIL usage.
- X
- X
- X Sendpsimail Exit statuses
- X ~~~~~~~~~~~~~~~~~~~~~~~~~
- X
- XIf all its connections failed, then Sendpsimail does not inform the user
- Xand exits with the status EX_TEMPFAIL [See include file sysexits.h.]
- XEX_TEMPFAIL is a signal to Sendmail to try to resend the message.
- XSendmail will continue to try for a predetermined number of times before
- Xgiving up. If some but not all connection attempts succeeded, then
- XSendpsimail must not exit with EX_TEMPFAIL. That would cause it to be
- Xinvoked with the same argument list once again resulting in a duplicate
- Xmessage to the destination user for whom transmission succeeded the
- Xfirst time. In that case, Sendpsimail exits with the status
- XEX_SOFTWARE. This causes Sendmail to return the message to the Sender.
- XIn such a case, Sendpsimail also mails the sender giving him a list of
- Xthe destination nodes to which it failed to connect. So the sender can
- Xresend the message only to those nodes to which Sendpsimail could not
- Xconnect.
- X
- XSome postmasters are fussy about the verbosity of mailers. They might
- Xnot like the mailing system to send the user two messages for every
- Xpartial success. (One from Sendmail returning the unsent message, the
- Xother from Sendpsimail showing which nodes it couldn't connect to) Such
- Xpostmasters can configure Sendmail to invoke Sendpsimail uniquely for
- Xeach destination address. This will ensure that there are no partial
- Xfailures.
- X
- X
- X Example Sendmail Configuration
- X ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- X
- XThe following is an extract from a sendmail.cf that shows the sort of
- Xchanges that might be necessary.
- X
- X---
- X.
- X.
- X.
- X#
- X# Define the PSI Mailer
- X#
- X
- XMpsi, P=/usr/local/mail/mailers/sendpsimail, F=FnDlMuL, S=0, R=0,
- X A=sendpsimail $u
- X.
- X.
- X.
- X
- X# Include the following in Ruleset 3
- X# Chop off domains. `D' must be defined locally by you. For example,
- X# here at Massey, we have
- X# CD massey massey.ac massey.ac.nz cc-server1
- X# under domain definitions
- X
- XR$+@psi-gateway.$=D $@$1@psi-gateway
- X.
- X.
- X.
- X
- X# Include the following line in Ruleset 0.
- X# Calls the Mailer for matching addresses
- X
- XR$+@psi-gateway $#psi$:$1 user@psiaddr
- X
- X---
- X
- X Charging for PSI MAIL usage:
- X ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- X
- XPSI mail, unlike SMTP generates a real charge. X.25 usage is charged by
- XTelecom under two categories: Duration and Volume. Luckily, the X.25
- Xserver on the system provides a convenient means of transferring charges
- Xto users. An ascii account file is created listing the duration and
- Xnumber of packets transferred for the user that made the connection.
- XShould Sendmail be run setuid to root, then each outgoing mail
- Xconnection will be made by Sendpsimail invoked as `root'. This will
- Xresult in the X.25 charges debited to `root' and the postmaster will end
- Xup paying for all the outgoing PSI mail. The solution is to run
- XSendmail setuid to the caller. This will cause the X.25 server to
- Xgenerate an accounting entry for the user and enable the postmaster to
- Xpass the charges on to him.
- X
- X
- X KNOWN BUGS AND SHORTCOMINGS
- X ~~~~~~~~~~~~~~~~~~~~~~~~~~~
- X
- XSendpsimail mysteriously dies upon receiving a SIGPROF signal
- Xoccasionally. It has been observed to occur whenever Sendpsimail and
- XRecvpsimail are active at the same time although we cannot establish
- Xthat it has never occurred when Sendpsimail has been active by itself.
- XBen Golding of Pyramid Computer Pty Ltd, Sydney, helped in narrowing
- Xdown the problem to a possible bug in the x.25 implementation on the
- XPyramid (1980 version). The include file /usr/src/x25.h shows that the
- Ximplementation uses signal 27 to signal an incoming call. Now signal 27
- Xis the same as SIGPROF which if not intercepted could cause a core dump.
- XThis problem has been patched up temporarily by trapping SIGPROF
- Xin Sendpsimail and tying it to a do-nothing function. A more
- Xsatisfactory solution to this problem would be nice.
- X
- XIt would be nice to have a dbm database of x25 addresses and Node names
- Xfor Sendmail. Then the user will not have to remember the x25 addresses
- Xof each node that mail must be sent to. An address would be of the form
- XNodename::user instead of Nodenumber::user. To reach someone at massey
- Xvia PSIMAIL for example, a user would just have to type
- XMassey::User@psi-gateway and not 6300006412::User@psi-gateway.
- X
- END_OF_FILE
- if test 13111 -ne `wc -c <'psimail/README'`; then
- echo shar: \"'psimail/README'\" unpacked with wrong size!
- fi
- # end of 'psimail/README'
- fi
- if test -f 'psimail/debugmsg.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'psimail/debugmsg.c'\"
- else
- echo shar: Extracting \"'psimail/debugmsg.c'\" \(4347 characters\)
- sed "s/^X//" >'psimail/debugmsg.c' <<'END_OF_FILE'
- X#ifndef lint
- X static char rcsid[] ="$Id: debugmsg.c version 1.0";
- X#endif
- X/*
- X * $Log debugmsg.c,v $
- X * debug module for the psi mailer
- X * anand
- X */
- X/*
- X * Copyright (c) 1991 Computing Services, Massey University,
- X * Palmerston North, New Zealand
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms, with or without
- X * modification, are permitted provided that the following conditions
- X * are met:
- X * 1. Redistributions of source code must retain the above copyright
- X * notice, this list of conditions and the following disclaimer.
- X * 2. Redistributions in binary form must reproduce the above copyright
- X * notice, this list of conditions and the following disclaimer in the
- X * documentation and/or other materials provided with the distribution.
- X * 3. All advertising materials mentioning features or use of this software
- X * must display the following acknowledgement:
- X * This product includes software developed by the Systems Software
- X * Support Group, Computing Services, Massey University,
- X * Palmerston North, NZ.
- X * 4. The name of Massey University may not be used to endorse or promote
- X * products derived from this software without specific prior written
- X * permission.
- X *
- X * THIS SOFTWARE IS PROVIDED BY COMPUTING SERVICES, MASSEY UNIVERSITY
- X * `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- X * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- X * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SMIS, MASSEY UNIVERSITY BE
- X * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- X * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- X * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- X * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- X * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- X * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- X * POSSIBILITY OF SUCH DAMAGE.
- X */
- X
- X#ifdef DEBUG
- X
- X#include <stdio.h>
- X#include <ctype.h>
- X#include <fcntl.h>
- X#include <strings.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <sys/syslog.h>
- X
- X#ifndef DEBUGDIR
- X# define DEBUGDIR "/tmp" /* Where to create debug files */
- X#endif
- X
- Xdebugmsg(fdd, s)
- Xint fdd;
- Xchar *s;
- X{
- X (void) write(fdd,s,strlen(s));
- X (void) write(fdd,"\n",1);
- X}
- X
- X/*
- X * xdebugmsg() prints c bytes of s in DOS debug style
- X */
- Xxdebugmsg(fdd, s,c)
- Xu_char *s;
- Xint c;
- X{
- X int i = 0, nlines = 0;
- X char ascbuf[32], *ap = ascbuf;
- X char buf[80], temp[16];
- X long count = 0L;
- X
- X ascbuf[0] = buf[0] = '\0';
- X while (c--) {
- X if (*s <= 127 && isprint(*s))
- X *ap++ = *s;
- X else
- X *ap++ = '.';
- X (void) sprintf(temp, "%02x ", (unsigned) *s & 0xff);
- X (void) strcat(buf, temp);
- X switch(++i) {
- X case 8:
- X (void) strcat(buf, "- ");
- X break;
- X case 16:
- X i = 0;
- X *ap = '\0';
- X (void) strcat(buf, " ");
- X (void) strcat(buf, ascbuf);
- X (void) strcat(buf, "\n");
- X (void) sprintf(temp, "%04X: ", count);
- X (void) write(fdd, temp, strlen(temp));
- X (void) write(fdd, buf, strlen(buf));
- X if (++nlines >= 8) {
- X nlines = 0;
- X (void) write(fdd, "\n", 1);
- X }
- X ascbuf[0] = buf[0] = '\0';
- X count += 16;
- X ap = ascbuf;
- X break;
- X default:
- X break;
- X }
- X ++s;
- X }
- X if (ap == ascbuf)
- X return;
- X *ap = '\0';
- X while (i++ < 16) {
- X (void) strcat(buf, " ");
- X if (i == 8)
- X (void) strcat(buf, " ");
- X }
- X (void) strcat(buf, " ");
- X (void) strcat(buf, ascbuf);
- X (void) strcat(buf, "\n");
- X (void) sprintf(temp, "%04X: ", count);
- X (void) write(fdd, temp, strlen(temp));
- X (void) write(fdd, buf, strlen(buf));
- X}
- X
- X/*
- X * opendebug() opens the debug file in the appropriate place.
- X */
- Xopendebug(prog)
- Xchar *prog;
- X{
- X int i, fdd;
- X char debugfile[128];
- X struct stat sbuf;
- X
- X for (i = 0; i < 100; i++) {
- X (void) sprintf(debugfile, "%s/%s.debug.%d", DEBUGDIR, prog, i);
- X if (!stat(debugfile, &sbuf))
- X continue;
- X fdd = open(debugfile, O_CREAT|O_TRUNC|O_WRONLY, 0666);
- X if (fdd < 0) {
- X syslog(LOG_ERR,"%s: Can't open %s: %m", prog, debugfile);
- X return -1;
- X }
- X break;
- X }
- X if (i == 100) {
- X syslog(LOG_ERR,"%s: Too many debug files in %s", prog, DEBUGDIR);
- X return -1;
- X }
- X debugmsg(fdd, "Started");
- X return fdd;
- X}
- X#endif
- END_OF_FILE
- if test 4347 -ne `wc -c <'psimail/debugmsg.c'`; then
- echo shar: \"'psimail/debugmsg.c'\" unpacked with wrong size!
- fi
- # end of 'psimail/debugmsg.c'
- fi
- if test -f 'psimail/str.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'psimail/str.c'\"
- else
- echo shar: Extracting \"'psimail/str.c'\" \(4633 characters\)
- sed "s/^X//" >'psimail/str.c' <<'END_OF_FILE'
- X/*
- X * $Log: str.c,v $
- X * Some string functions.
- X * Venkataraman Anand, Nov 91
- X */
- X/*
- X * Copyright (c) 1991 Computing Services, Massey University,
- X * Palmerston North, New Zealand
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms, with or without
- X * modification, are permitted provided that the following conditions
- X * are met:
- X * 1. Redistributions of source code must retain the above copyright
- X * notice, this list of conditions and the following disclaimer.
- X * 2. Redistributions in binary form must reproduce the above copyright
- X * notice, this list of conditions and the following disclaimer in the
- X * documentation and/or other materials provided with the distribution.
- X * 3. All advertising materials mentioning features or use of this software
- X * must display the following acknowledgement:
- X * This product includes software developed by the Systems Software
- X * Support Group, Computing Services, Massey University,
- X * Palmerston North, NZ.
- X * 4. The name of Massey University may not be used to endorse or promote
- X * products derived from this software without specific prior written
- X * permission.
- X *
- X * THIS SOFTWARE IS PROVIDED BY COMPUTING SERVICES, MASSEY UNIVERSITY
- X * `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- X * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- X * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MASSEY UNIVERSITY BE
- X * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- X * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- X * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- X * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- X * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- X * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- X * POSSIBILITY OF SUCH DAMAGE.
- X */
- X
- X#include <stdio.h>
- X#include <string.h>
- X#include "str.h"
- X
- X#define isupper(c) ('A' <= (c) && (c) <= 'Z')
- X#define tolower(c) ((isupper(c))? (c)-'A'+'a' : (c))
- X
- Xstricmp (s, t)
- Xregister char *s, *t;
- X{
- X while (tolower (*s) == tolower (*t)) {
- X if (!*s)
- X return 0;
- X ++s; ++t;
- X }
- X return (tolower (*s) - tolower (*t));
- X}
- X
- Xstrnicmp (s, t, n)
- Xregister char *s, *t;
- X{
- X while (tolower (*s) == tolower (*t)) {
- X if (!*s || !--n)
- X return 0;
- X ++s; ++t;
- X }
- X return (tolower (*s) - tolower (*t));
- X}
- X
- Xchar *strsave (s) /* save string s */
- Xchar *s;
- X{
- X char *malloc();
- X register char *p;
- X
- X if ((p = malloc ((unsigned) strlen (s) + 1)) != NULL )
- X (void) strcpy (p, s);
- X return (p);
- X}
- X
- Xchar *strtok (s, delims) /* return successive tokens from s */
- Xchar *s, *delims;
- X{
- X static char *t = NULL;
- X register char *p, *temp;
- X
- X if (s != NULL) /* new string */
- X t = s;
- X
- X /* preliminary check */
- X if (t == NULL && s == NULL)
- X return NULL;
- X
- X /* skip leading delims */
- X while (*t && strchr (delims, *t) != NULL)
- X ++t;
- X if (!*t) /* string ends after delims */
- X return (NULL); /* no more tokens */
- X p = t;
- X while (*p && strchr (delims, *p) == NULL)
- X ++p;
- X if (!*p) { /* end of string */
- X p = t;
- X t = NULL; /* so next call returns NULL */
- X return p;
- X }
- X
- X *p = '\0';
- X temp = p; /* swap p and t so t points after new token */
- X p = t;
- X t = temp;
- X ++t;
- X
- X return p;
- X}
- X
- Xchar *stristr (s, p) /* return p in s (ignore case) */
- Xchar *s, *p;
- X{
- X register int i;
- X
- X i = strlen (p);
- X while (*s) {
- X if (!strnicmp (s, p, i))
- X return s;
- X ++s;
- X }
- X return (NULL);
- X}
- X
- Xchar *strrmc(s,c)
- Xregister char *s;
- X{
- X register char *p;
- X
- X if (!c)
- X return s;
- X while ((p = strchr(s,c)) != NULL)
- X (void) strcpy(p,p+1);
- X return s;
- X}
- X
- Xchar *strchr (s, c) /* return first occurrence of c in s */
- Xregister char *s; /* NULL otherwise */
- X{
- X while (*s != c && *s)
- X ++s;
- X /*
- X * This last 'if' is necessary because the loop is exited when the
- X * end of s is reached.
- X * If c was '\0' it does match a character in s and therefore a test
- X * is done to determine that condition.
- X */
- X if (*s == c)
- X return s;
- X else
- X return (NULL);
- X
- X}
- X
- Xchar *strrchr (s, c) /* return last occurrence of c in s */
- Xchar *s; /* NULL otherwise */
- Xint c;
- X{
- X register char *p;
- X
- X p = s;
- X while (*s)
- X ++s; /* get to the end of s */
- X while (s >= p && *s != c)
- X --s;
- X if (s < p)
- X return (NULL);
- X else
- X return s;
- X}
- X
- X
- X
- X
- X
- END_OF_FILE
- if test 4633 -ne `wc -c <'psimail/str.c'`; then
- echo shar: \"'psimail/str.c'\" unpacked with wrong size!
- fi
- # end of 'psimail/str.c'
- fi
- if test -f 'psimail/str.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'psimail/str.h'\"
- else
- echo shar: Extracting \"'psimail/str.h'\" \(2082 characters\)
- sed "s/^X//" >'psimail/str.h' <<'END_OF_FILE'
- X/*
- X * $Log: str.h,v $
- X * Some string function declarations
- X * Venkataraman Anand, Nov 91
- X */
- X
- X/*
- X * Copyright (c) 1991 Computing Services, Massey University,
- X * Palmerston North, New Zealand
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms, with or without
- X * modification, are permitted provided that the following conditions
- X * are met:
- X * 1. Redistributions of source code must retain the above copyright
- X * notice, this list of conditions and the following disclaimer.
- X * 2. Redistributions in binary form must reproduce the above copyright
- X * notice, this list of conditions and the following disclaimer in the
- X * documentation and/or other materials provided with the distribution.
- X * 3. All advertising materials mentioning features or use of this software
- X * must display the following acknowledgement:
- X * This product includes software developed by the Systems Software
- X * Support Group, Computing Services, Massey University,
- X * Palmerston North, NZ.
- X * 4. The name of Massey University may not be used to endorse or promote
- X * products derived from this software without specific prior written
- X * permission.
- X *
- X * THIS SOFTWARE IS PROVIDED BY COMPUTING SERVICES, MASSEY UNIVERSITY
- X * `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- X * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- X * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MASSEY UNIVERSITY BE
- X * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- X * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- X * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- X * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- X * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- X * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- X * POSSIBILITY OF SUCH DAMAGE.
- X */
- X
- Xchar *strchr();
- Xchar *strrmc();
- Xchar *strsave();
- Xchar *stristr();
- Xchar *strtok();
- Xchar *strtrunc();
- Xchar *strrchr();
- END_OF_FILE
- if test 2082 -ne `wc -c <'psimail/str.h'`; then
- echo shar: \"'psimail/str.h'\" unpacked with wrong size!
- fi
- # end of 'psimail/str.h'
- fi
- echo shar: End of archive 2 \(of 2\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked both archives.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-