[comp.sources.amiga] v90i051: uucp 1.03D - unix compatible uucp/mail/news system, Part07/16

Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator) (02/04/90)

Submitted-by: overload!dillon (Matt Dillon)
Posting-number: Volume 90, Issue 051
Archive-name: unix/uucp-1.03d/part07

#!/bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 7 (of 16)."
# Contents:  man/GNU-LICENSE src/dmail/execom.c src/uucico/sysdep.c
#   src/uuser/uuser.c
# Wrapped by tadguy@xanth on Sat Feb  3 20:51:12 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'man/GNU-LICENSE' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man/GNU-LICENSE'\"
else
echo shar: Extracting \"'man/GNU-LICENSE'\" \(12488 characters\)
sed "s/^X//" >'man/GNU-LICENSE' <<'END_OF_FILE'
X
X		    GNU GENERAL PUBLIC LICENSE
X		     Version 1, February 1989
X
X Copyright (C) 1989 Free Software Foundation, Inc.
X                    675 Mass Ave, Cambridge, MA 02139, USA
X Everyone is permitted to copy and distribute verbatim copies
X of this license document, but changing it is not allowed.
X
X			    Preamble
X
X  The license agreements of most software companies try to keep users
Xat the mercy of those companies.  By contrast, our General Public
XLicense is intended to guarantee your freedom to share and change free
Xsoftware--to make sure the software is free for all its users.  The
XGeneral Public License applies to the Free Software Foundation's
Xsoftware and to any other program whose authors commit to using it.
XYou can use it for your programs, too.
X
X  When we speak of free software, we are referring to freedom, not
Xprice.  Specifically, the General Public License is designed to make
Xsure that you have the freedom to give away or sell copies of free
Xsoftware, that you receive source code or can get it if you want it,
Xthat you can change the software or use pieces of it in new free
Xprograms; and that you know you can do these things.
X
X  To protect your rights, we need to make restrictions that forbid
Xanyone to deny you these rights or to ask you to surrender the rights.
XThese restrictions translate to certain responsibilities for you if you
Xdistribute copies of the software, or if you modify it.
X
X  For example, if you distribute copies of a such a program, whether
Xgratis or for a fee, you must give the recipients all the rights that
Xyou have.  You must make sure that they, too, receive or can get the
Xsource code.  And you must tell them their rights.
X
X  We protect your rights with two steps: (1) copyright the software, and
X(2) offer you this license which gives you legal permission to copy,
Xdistribute and/or modify the software.
X
X  Also, for each author's protection and ours, we want to make certain
Xthat everyone understands that there is no warranty for this free
Xsoftware.  If the software is modified by someone else and passed on, we
Xwant its recipients to know that what they have is not the original, so
Xthat any problems introduced by others will not reflect on the original
Xauthors' reputations.
X
X  The precise terms and conditions for copying, distribution and
Xmodification follow.
X
X		    GNU GENERAL PUBLIC LICENSE
X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
X
X  0. This License Agreement applies to any program or other work which
Xcontains a notice placed by the copyright holder saying it may be
Xdistributed under the terms of this General Public License.  The
X"Program", below, refers to any such program or work, and a "work based
Xon the Program" means either the Program or any work containing the
XProgram or a portion of it, either verbatim or with modifications.  Each
Xlicensee is addressed as "you".
X
X  1. You may copy and distribute verbatim copies of the Program's source
Xcode as you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy an appropriate copyright notice and
Xdisclaimer of warranty; keep intact all the notices that refer to this
XGeneral Public License and to the absence of any warranty; and give any
Xother recipients of the Program a copy of this General Public License
Xalong with the Program.  You may charge a fee for the physical act of
Xtransferring a copy.
X
X  2. You may modify your copy or copies of the Program or any portion of
Xit, and copy and distribute such modifications under the terms of Paragraph
X1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating that
X    you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish, that
X    in whole or in part contains the Program or any part thereof, either
X    with or without modifications, to be licensed at no charge to all
X    third parties under the terms of this General Public License (except
X    that you may choose to grant warranty protection to some or all
X    third parties, at your option).
X
X    c) If the modified program normally reads commands interactively when
X    run, you must cause it, when started running for such interactive use
X    in the simplest and most usual way, to print or display an
X    announcement including an appropriate copyright notice and a notice
X    that there is no warranty (or else, saying that you provide a
X    warranty) and that users may redistribute the program under these
X    conditions, and telling the user how to view a copy of this General
X    Public License.
X
X    d) You may charge a fee for the physical act of transferring a
X    copy, and you may at your option offer warranty protection in
X    exchange for a fee.
X
XMere aggregation of another independent work with the Program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other work under the scope of these terms.
X
X  3. You may copy and distribute the Program (or a portion or derivative of
Xit, under Paragraph 2) in object code or executable form under the terms of
XParagraphs 1 and 2 above provided that you also do one of the following:
X
X    a) accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    b) accompany it with a written offer, valid for at least three
X    years, to give any third party free (except for a nominal charge
X    for the cost of distribution) a complete machine-readable copy of the
X    corresponding source code, to be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    c) accompany it with the information you received as to where the
X    corresponding source code may be obtained.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form alone.)
X
XSource code for a work means the preferred form of the work for making
Xmodifications to it.  For an executable file, complete source code means
Xall the source code for all modules it contains; but, as a special
Xexception, it need not include source code for modules which are standard
Xlibraries that accompany the operating system on which the executable
Xfile runs, or for standard header files or definitions files that
Xaccompany that operating system.
X
X  4. You may not copy, modify, sublicense, distribute or transfer the
XProgram except as expressly provided under this General Public License.
XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
Xthe Program is void, and will automatically terminate your rights to use
Xthe Program under this License.  However, parties who have received
Xcopies, or rights to use copies, from you under this General Public
XLicense will not have their licenses terminated so long as such parties
Xremain in full compliance.
X
X  5. By copying, distributing or modifying the Program (or any work based
Xon the Program) you indicate your acceptance of this license to do so,
Xand all its terms and conditions.
X
X  6. Each time you redistribute the Program (or any work based on the
XProgram), the recipient automatically receives a license from the original
Xlicensor to copy, distribute or modify the Program subject to these
Xterms and conditions.  You may not impose any further restrictions on the
Xrecipients' exercise of the rights granted herein.
X
X  7. The Free Software Foundation may publish revised and/or new versions
Xof the General Public License from time to time.  Such new versions will
Xbe similar in spirit to the present version, but may differ in detail to
Xaddress new problems or concerns.
X
XEach version is given a distinguishing version number.  If the Program
Xspecifies a version number of the license which applies to it and "any
Xlater version", you have the option of following the terms and conditions
Xeither of that version or of any later version published by the Free
XSoftware Foundation.  If the Program does not specify a version number of
Xthe license, you may choose any version ever published by the Free Software
XFoundation.
X
X  8. If you wish to incorporate parts of the Program into other free
Xprograms whose distribution conditions are different, write to the author
Xto ask for permission.  For software which is copyrighted by the Free
XSoftware Foundation, write to the Free Software Foundation; we sometimes
Xmake exceptions for this.  Our decision will be guided by the two goals
Xof preserving the free status of all derivatives of our free software and
Xof promoting the sharing and reuse of software generally.
X
X			    NO WARRANTY
X
X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
XREPAIR OR CORRECTION.
X
X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
XPOSSIBILITY OF SUCH DAMAGES.
X
X		     END OF TERMS AND CONDITIONS
X
X	Appendix: How to Apply These Terms to Your New Programs
X
X  If you develop a new program, and you want it to be of the greatest
Xpossible use to humanity, the best way to achieve this is to make it
Xfree software which everyone can redistribute and change under these
Xterms.
X
X  To do so, attach the following notices to the program.  It is safest to
Xattach them to the start of each source file to most effectively convey
Xthe exclusion of warranty; and each file should have at least the
X"copyright" line and a pointer to where the full notice is found.
X
X    <one line to give the program's name and a brief idea of what it does.>
X    Copyright (C) 19yy  <name of author>
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 as published by
X    the Free Software Foundation; either version 1, or (at your option)
X    any later version.
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
XAlso add information on how to contact you by electronic and paper mail.
X
XIf the program is interactive, make it output a short notice like this
Xwhen it starts in an interactive mode:
X
X    Gnomovision version 69, Copyright (C) 19xx name of author
X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
X    This is free software, and you are welcome to redistribute it
X    under certain conditions; type `show c' for details.
X
XThe hypothetical commands `show w' and `show c' should show the
Xappropriate parts of the General Public License.  Of course, the
Xcommands you use may be called something other than `show w' and `show
Xc'; they could even be mouse-clicks or menu items--whatever suits your
Xprogram.
X
XYou should also get your employer (if you work as a programmer) or your
Xschool, if any, to sign a "copyright disclaimer" for the program, if
Xnecessary.  Here a sample; alter the names:
X
X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
X  program `Gnomovision' (a program to direct compilers to make passes
X  at assemblers) written by James Hacker.
X
X  <signature of Ty Coon>, 1 April 1989
X  Ty Coon, President of Vice
X
XThat's all there is to it!
END_OF_FILE
if test 12488 -ne `wc -c <'man/GNU-LICENSE'`; then
    echo shar: \"'man/GNU-LICENSE'\" unpacked with wrong size!
fi
# end of 'man/GNU-LICENSE'
fi
if test -f 'src/dmail/execom.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/dmail/execom.c'\"
else
echo shar: Extracting \"'src/dmail/execom.c'\" \(12732 characters\)
sed "s/^X//" >'src/dmail/execom.c' <<'END_OF_FILE'
X
X/*
X *  EXECOM.C
X *
X *  (C) Copyright 1985-1990 by Matthew Dillon,  All Rights Reserved.
X *
X *  Routines to parse and execute command lines.
X *
X *  Global Routines:	DO_COMMAND()
X *			EXEC_COMMAND()
X *			FIX()
X *
X *  Static Routines:	E_COMMAND()
X *			BREAKOUT()
X *			FIND_COMMAND()
X */
X
X
X#include <pwd.h>
X#include <stdio.h>
X#include <string.h>
X#include "dmail.h"
X#include "execom.h"
X
X#define F_EXACT     0
X#define F_ABBR	    1
X#define SCRBUF	    1024
X
Xextern char *breakout();
X
Xextern int do_quit(), do_exit(), do_help(), do_list(), do_setlist();
Xextern int do_select(), do_type(), do_header(), do_next(), do_mark();
Xextern int do_unmark(), do_reply(), do_delnext(), do_rlist();
Xextern int do_write(), do_shell(), do_set_var(), do_unset_var();
Xextern int do_number(), do_cd(), do_source(), do_defer(), do_echo();
Xextern int do_go(), do_break();
X
Xextern int do_if(), do_else(), do_endif();
Xextern int do_ver(), do_delprev();
X
Xstruct COMMAND Command[] = {
X	do_number   , 0,	0,		    "",
X	do_mark     , 0,	ST_DELETED,	    "delete",
X	do_unmark   , 0,	ST_DELETED,	    "undelete",
X	do_header   , 0,	0,		    "header",
X	do_type     , 0,	0,		    "type",
X	do_echo     , 0,	0,		    "echo",
X	do_go	    , 0,	0,		    "go",
X	do_reply    , 0,	R_REPLY,	    "reply",
X	do_reply    , 0,	R_INCLUDE,	    "Reply",
X	do_reply    , 0,	R_MAIL, 	    "mail",
X	do_reply    , 0,	R_FORWARD,	    "forward",
X	do_select   , 0,	0,		    "select",
X	do_select   , 0,	1,		    "reselect",
X	do_defer    , 0,	1,		    "defer",
X	do_list     , 0,	0,		    "list",
X	do_rlist    , 0,	0,		    "rlist",
X	do_next     , 0,	1,		    "next",
X	do_next     , 0,	-1,		    "back",
X	do_next     , 0,	2,		    "_next",
X	do_next     , 0,	-2,		    "_back",
X	do_delnext  , 0,	0,		    "dt",
X	do_delprev  , 0,	0,		    "db",
X	do_set_var  , 0,	0,		    "set",
X	do_unset_var, 0,	0,		    "unset",
X	do_set_var  , 0,	1,		    "alias",
X	do_unset_var, 0,	1,		    "unalias",
X	do_set_var  , C_NO,	2,		    "malias",
X	do_unset_var, C_NO,	2,		    "munalias",
X	do_setlist  , 0,	0,		    "setlist",
X	do_cd	    , 0,	0,		    "cd",
X	do_source   , 0,	0,		    "source",
X	do_unmark   , 0,	ST_READ | ST_STORED,"preserve",
X	do_mark     , 0,	ST_READ,	    "mark",
X	do_mark     , 0,	ST_TAG, 	    "tag",
X	do_unmark   , 0,	ST_TAG, 	    "untag",
X	do_unmark   , 0,	ST_STORED,	    "unwrite",
X	do_write    , 0,	0,		    "write",
X	do_shell    , 0,	0,		    "!",
X	do_exit     , 0,	0,		    "x",
X	do_quit     , 0,	0,		    "quit",
X	do_exit     , 0,	1,		    "xswitch",
X	do_quit     , 0,	1,		    "qswitch",
X	do_help     , 0,	0,		    "help",
X	do_help     , 0,	0,		    "?",
X	do_break    , 0,	0,		    "nobreak",
X	do_break    , 0,	1,		    "breakok",
X	do_if	    , C_COND,	0,		    "if",
X	do_else     , C_COND,	0,		    "else",
X	do_endif    , C_COND,	0,		    "endif",
X	do_ver	    , 0,	0,		    "version",
X	NULL	    , 0,	0,		    NULL };
X
Xchar *Desc[] = {
X	"",
X	"<list>                   mark messages for deletion",
X	"<list>                   UNDELETE & UNMARK messages",
X	"[msg]                    Display header of a message",
X	"[msg]                    type a message",
X	"args....                 Echo to the screen",
X	"#                        Go to a message, don't print out",
X	"                         reply to mail",
X	"                         reply to mail, include recv'd text",
X	"user user ...            send mail to users",
X	"user user ...            forward mail to users",
X	"Field [!]match [match][ , Field match.]  SELECT from entire message list",
X	"Field [!]match [match][ , Field match.]  SELECT from current message list",
X	"                         De-select any read messages",
X	"<list>                   list mail as specified by SETLIST",
X	"[+/-][N]                 list relative to current position",
X	"[msg]                    type/header next or message #",
X	"[msg]                    type/header previous or message #",
X	"[msg]                    go to next or message #",
X	"[msg]                    go to previous or message #",
X	"                         delete current, type next",
X	"                         delete current, type prev",
X	"[var [string]]           set a variable",
X	"var var var ...          unset a variable",
X	"[var [string]]           set an alias",
X	"var var var ...          unset an alias",
X	"[var [string]]           set a mail alias",
X	"var var var ...          unset a mail alias",
X	"[-s] [cols] Field [cols] Field...    SET LIST format for LIST",
X	"path                     CD to a directory",
X	"file                     Source a file",
X	"<list>                   UNREAD & UNMARK messages",
X	"<list>                   mark messages as 'read'",
X	"<list>                   tag messages for whatever",
X	"<list>                   untag messages",
X	"<list>                   unwrite messages",
X	"file <list>              append messages to a file, delete on quit",
X	"[command]                execute a shell [command]",
X	"                         EXIT, do not save changes",
X	"                         QUIT, update files",
X	"from to                  Exit and switch to a new from/to file",
X	"from to                  Quit and switch to a new from/to file",
X	"[topic]                  help on a topic",
X	"[topic]                  alternate form of HELP",
X	"                         Disable INTR (stackable)",
X	"                         Enable  INTR (stackable)",
X	"[!]variable              conditionals (stackable)",
X	"",
X	"",
X	"                         Print the version number",
X	NULL };
X
X
Xdo_command()
X{
X    static char comline[1024];
X
X    if (Current >= 0 && Current < Entries)
X	printf("%3d:", Entry[Current].no);
X    else
X	printf("nul:");
X    fflush (stdout);
X    if (gets (comline) == NULL)
X	done (1);
X    exec_command(comline);
X    return (1);
X}
X
X
X
X/*
X * EXEC_COMMAND()
X *
X *
X */
X
X
Xstruct MLIST {
X    struct MLIST *next;
X};
X
Xstatic struct MLIST *Mlist;
X
Xchar *
Xmpush(amount)
Xint amount;
X{
X    struct MLIST *ml;
X
X    push_break();
X    ml = (struct MLIST *)malloc (amount + sizeof(*Mlist));
X    ml->next = Mlist;
X    Mlist = ml;
X    pop_break();
X    return ((char *)Mlist + sizeof(*Mlist));
X}
X
X
Xchar *
Xmpop()
X{
X    char *old = NULL;
X
X    push_break();
X    if (Mlist == NULL) {
X	puts ("MLIST INTERNAL ERROR");
X    } else {
X	old = (char *)Mlist + sizeof(*Mlist);
X	xfree (Mlist);
X	Mlist = Mlist->next;
X    }
X    pop_break();
X    return (old);
X}
X
Xvoid
Xmrm()
X{
X    push_break();
X    while (Mlist) {
X	xfree (Mlist);
X	Mlist = Mlist->next;
X    }
X    pop_break();
X}
X
X
Xexec_command(base)
Xchar *base;
X{
X    char *str;
X    int i;
X
X    if (push_base()) {
X	push_break();
X	pop_base();
X	mrm();
X	pop_break();
X	return (-1);
X    }
X    strcpy (str = mpush(strlen(base) + 1), base);
X    i = e_command(str);
X    if (mpop() != str)
X	puts ("POP ERROR");
X    pop_base();
X    return (i);
X}
X
X
Xstatic
Xe_command(base)
Xchar *base;
X{
X    char *com, *start, *avline, *alias;
X    int flag = 0;
X    int i, pcount, len, ccno;
X
Xloop:
X    com = breakout (&base, &flag);
X    if (*com == '\0') {
X	if (flag > 1)
X	    return (1);
X	goto loop;
X    }
X    if ((ccno = find_command(com, F_EXACT)) < 0) {
X	if (*com == '$')
X	    alias = get_var (LEVEL_SET, com + 1);
X	else
X	    alias = get_var (LEVEL_ALIAS, com);
X	if (alias == NULL) {
X	    if ((ccno = find_command (com, F_ABBR)) < 0) {
X		if (!XDisable)
X		    printf ("%s Command Not found\n", com);
X		return (XDisable ? 1 : -1);
X	    } else {
X		goto good_command;
X	    }
X	}
X
X	/* At this point, base points to arguments */
X
X	start = (flag == 0) ? base : "";
X	while (flag == 0) {             /* find ';' or end of string        */
X	    flag = -1;			/* disable breakout's "" terminator */
X	    breakout (&base, &flag);
X	}
X
X	/*
X	 * At this point, start points to all arguments, base set up for next
X	 * string
X	 */
X
X	if (*alias == '%') {
X	    int xx = 0;
X	    char *select;
X
X	    alias = strcpy (mpush (strlen(alias) + 1), alias);
X	    select = breakout (&alias, &xx);
X	    set_var (LEVEL_SET, select + 1, start);
X	    i = e_command (alias);
X	    unset_var (LEVEL_SET, select + 1);
X	    mpop();
X	} else {
X	    com = mpush (strlen(alias) + strlen(start) + 2);
X	    strcpy (com, alias);
X	    strcat (com, (flag == 1) ? ";" : " ");
X	    strcat (com, start);
X	    i = e_command (com);
X	    if (mpop() != com)
X		puts ("ME BAE ERROR");
X	}
X	if (i < 0)
X	    return (-1);
X	if (flag > 1)
X	    return (1);
X	goto loop;
X    }
Xgood_command:
X    if (XDisable && (Command[ccno].stat & C_COND) == 0) {
X	while (flag < 1)
X	    breakout (&base, &flag);
X	if (flag > 1)
X	    return (1);
X	goto loop;
X    }
X    if (Command[ccno].stat & C_NO  &&  XDebug == 0) {
X	printf ("%s  Is currently being developed\n", Command[ccno].name);
X	return (-1);
X    }
X    if (XDebug)
X	printf ("Good command, Raw: %s\n", com);
X    i = pcount = 0;
X    av[i] = mpush (strlen(com) + 1);
X    ++pcount;
X    strcpy (av[i++], com);
X    while (flag < 1) {
X	com = breakout (&base, &flag);
X	if (XDebug)
X	    printf ("BREAKOUT %d %s\n", strlen(com), com);
X	if (*com == '\0')
X	    continue;
X	switch (*com) {
X	case '~':
X	    if (com[1] == '/'  ||  com[1] == '\0') {
X		av[i] = mpush (strlen(home_dir) + strlen(com + 1) + 1);
X		++pcount;
X		strcpy (av[i], home_dir);
X		strcat (av[i], com + 1);
X	    } else {
X		struct passwd *passwd;
X		char *user = com;
X
X		while (*com) {
X		    if (*com == '/') {
X			*com = '\0';
X			++com;
X			break;
X		    }
X		    ++com;
X		}
X		if ((passwd = getpwnam(user)) == NULL) {
X		    printf ("USER %s Not found\n", user);
X		    while (pcount--)
X			mpop();
X		    return (-1);
X		}
X		av[i] = mpush (strlen(passwd->pw_dir) + strlen(com) + 2);
X		++pcount;
X		strcpy (av[i], passwd->pw_dir);
X		if (*com) {
X		    strcat (av[i], "/");
X		    strcat (av[i], com);
X		}
X	    }
X	    break;
X	case '\"':
X	    av[i] = com + 1;
X	    while (*++com && *com != '\"');
X	    *com = '\0';
X	    break;
X	case '$':
X	    if (*(com + 1) == '$') {
X		av[i] = getenv(com + 2);
X		if (av[i] == NULL) {
X		    printf ("Env. Var %s not found\n", com + 2);
X		    av[i] = com;
X		}
X#ifdef AMIGA
X		av[i] = strcpy (mpush(strlen(av[i]) + 1), av[i]);
X		++pcount;
X#endif
X	    }  else {
X		av[i] = get_var (LEVEL_SET, com + 1);
X		if (av[i] == NULL)
X		    av[i] = com;
X		av[i] = strcpy (mpush(strlen(av[i]) + 1), av[i]);
X		++pcount;
X	    }
X	    break;
X	default:
X	    av[i] = com;
X	    break;
X	}
X	++i;
X    }
X    av[i] = NULL;
X    ac = i;
X    for (len = 0, i = 0; i < ac; ++i)
X	len += strlen (av[i]) + 1;
X    avline = mpush (len + 1);
X    *avline = '\0';
X    for (i = 0; i < ac; ++i) {
X	strcat (avline, av[i]);
X	if (i + 1 < ac)
X	    strcat (avline, " ");
X    }
X    if (XDebug)
X	printf ("DEST: %s\n", avline);
X    i = (*Command[ccno].func)(avline, Command[ccno].val);
X    if (mpop() != avline)
X	puts ("AVLINE ERROR");
X    while (pcount--)
X	mpop();
X    fix();
X    if (i < 0)
X	return (i);
X    if (flag < 2)
X	goto loop;
X    return (1);
X}
X
X
X/*
X * BREAKOUT
X *
X * Breakout next argument.  If FLAG is set to 1 on return, the argument
X * returned is the last in the command.  If FLAG is set to 2 on return, the
X * argument returned is the last, period.
X *
X */
X
Xstatic char *
Xbreakout(base, flag)
Xint *flag;
Xchar **base;
X{
X    register char *str, *scr;
X
Xloop:
X    str = *base;			/* next start		*/
X    while (*str == ' ' || *str == 9)    /* skip spaces and such */
X	++str;
X    switch (*str) {
X    case '\0':                          /* no more arguments    */
X	*flag = 2;
X	*base = str;
X	return (str);
X    case ';':                           /* no more args in this command */
X	*flag = 1;
X	*str = '\0';
X	*base = str + 1;
X	return (str);
X    }
X    scr = str;
X    for (;;) {                          /* valid argument of somesort   */
X	switch (*scr) {
X	case ' ':
X	case 9:
X	    if (*flag >= 0)
X		*scr = '\0';
X	    *base = scr + 1;
X	    *flag = 0;
X	    return (str);
X	case '\"':
X	    ++scr;
X	    while (*scr && (*scr++ != '\"'));   /* place to end of quote */
X	    break;
X	case '\0':
X	    *flag = 2;
X	    *base = scr;
X	    return (str);
X	case ';':
X	    *flag = 1;
X	    *base = scr + 1;
X	    *scr = '\0';
X	    return (str);
X	default:
X	    ++scr;
X	}
X    }
X}
X
X
X
Xfix()
X{
X    register int i;
X
X    for (i = (Current < 0) ? 0 : Current; i < Entries; ++i) {
X	if (Entry[i].no  &&  !(Entry[i].status & ST_DELETED)) {
X	    Current = i;
X	    return (1);
X	}
X    }
X    if (Current >= Entries) {
X	Current = Entries - 1;
X    /* Can become -1 if no entries  */
X    }
X    for (i = Current; i >= 0; --i) {
X	if (Entry[i].no  &&  !(Entry[i].status & ST_DELETED)) {
X	    Current = i;
X	    return (-1);
X	}
X    }
X    Current = -1;
X    return (-1);
X}
X
X
Xstatic
Xfind_command(str, arg)
Xchar *str;
Xint arg;
X{
X    int i;
X    int len = strlen (str);
X
X    if (*str >= '0'  &&  *str <= '9')
X	return (0);
X    for (i = 0; Command[i].func; ++i) {
X	if (strncmp (str, Command[i].name, len) == 0) {
X	    if (arg == F_ABBR)
X		return (i);
X	    if (strcmp (str, Command[i].name) == 0)
X		return (i);
X	    return (-1);
X	}
X    }
X    return (-1);
X}
X
END_OF_FILE
if test 12732 -ne `wc -c <'src/dmail/execom.c'`; then
    echo shar: \"'src/dmail/execom.c'\" unpacked with wrong size!
fi
# end of 'src/dmail/execom.c'
fi
if test -f 'src/uucico/sysdep.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/uucico/sysdep.c'\"
else
echo shar: Extracting \"'src/uucico/sysdep.c'\" \(11298 characters\)
sed "s/^X//" >'src/uucico/sysdep.c' <<'END_OF_FILE'
X
X/*
X * @(#)sysdep.amiga        Version Amiga 0.1     87/09/20
X *
X * (C) Copyright 1987 by John Gilmore
X * Copying and use of this program are controlled by the terms of the Free
X * Software Foundation's GNU Emacs General Public License.
X *
X *  Amiga Changes Copyright 1988 by William Loftus. All rights reserved.
X *  Additional chgs Copyright 1989 by Matthew Dillon, All Rights Reserved.
X */
X
X#include "/version.h"
X
Xstatic char *Version = "@(#)sysdep.amiga gnuucp" VERSION ".01";
X
X/*
X *  Split out of uuslave.c by John Gilmore, 8 August 1987.
X *  ported to the Amiga by William Loftus, 20 September 1987.
X *  rewritten by Matthew Dillon, October 1989
X */
X
X/* FIXME -- System dependent defines (not really -- should be in a .h) */
X/*
X * Timeout for raw characters -- if we don't hear a char within BYTE_TIMEOUT
X * seconds, we assume the other side has gone away.  Has nothing to do with
X * retransmission timeouts (if any!).
X */
Xextern int debug;
X
X/* Amiga */
X#include "uucp.h"
X#include "modem.h"
X#include <exec/types.h>
X#include <ctype.h>
X#include <fcntl.h>
X#include <exec/exec.h>
X#include <exec/devices.h>
X#include <devices/serial.h>
X#include <devices/keymap.h>
X#include <devices/timer.h>
X#include <hardware/cia.h>
X#include <libraries/dos.h>
X#include <signal.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <pwd.h>
X#include <proto/exec.h>
X
X#define NAMESIZE 128
X#define FAILURE  1
X
Xvoid printc();
X
Xextern struct MsgPort *CreatePort();
Xstruct IOExtSer Iosr;
Xstruct IOExtSer Iosw;
Xstruct IOExtSer Ioss;
Xstruct timerequest Iot0;
Xchar   *OldTaskName;
X
Xchar	*DeviceName = "serial.device";
Xlong	DeviceUnit = 0;
X
Xunsigned char	XInBuf[256];	   /*  for xgetc() */
Xshort	XInIdx = 0;
Xshort	XInLen = 0;
Xshort	IoswIP = 0;
X
Xshort	InExitRoutine = 0;
Xshort	debugRead = 0;
X
Xextern char path[];
Xextern int Getty;
Xextern int IgnoreCD;
X
Xvoid set_baud();
Xvoid OpenSerial();
Xvoid CloseSerial();
Xvoid xexit();
X
XCXBRK()
X{
X    return(0);
X}
X
Xint
Xopenout(acu, baud)
Xchar *acu;
Xint  baud;
X{
X    set_baud(baud);
X
X    return SUCCESS;
X}
X
X/*
X * Basement level I/O routines
X *
X * xwrite() writes a character string to the serial port
X * xgetc() returns a character from the serial port, or an EOF for timeout.
X * sigint() restores the state of the serial port on exit.
X */
X
Xint
Xsigint()
X{
X    xexit(1);
X    return(0);
X}
X
X
Xvoid
Xcleanup()
X{
X    xexit(0);
X}
X
Xint
Xxdatardy()
X{
X    if (XInIdx != XInLen)
X	return(1);
X    CheckCarrier();
X    return (Ioss.IOSer.io_Actual > 0);
X}
X
Xint
Xxgetc(byteto)
X{
X    int ch, n;
X    long smask;
X    long tmask;
X    short bytetimeout;
X
Xtop:
X    if (XInIdx != XInLen) {
X	if (debug > 8) {
X	    if (debugRead == 0)
X		printf("\nREAD: ");
X	    debugRead = 1;
X	    printc(XInBuf[XInIdx]);
X	}
X	return((int)XInBuf[XInIdx++]);
X    }
X    XInIdx = 0;
X    XInLen = 0;
X
X    if (!CheckCarrier())                        /*  carrier lost?     */
X	return(EOF);
X
X    if ((n = Ioss.IOSer.io_Actual) > 0) {       /*  at least one..    */
X	Iosr.IOSer.io_Command = CMD_READ;
X	Iosr.IOSer.io_Data = (APTR)XInBuf;
X	if (n > sizeof(XInBuf))
X	    n = sizeof(XInBuf);
X	Iosr.IOSer.io_Length = n;
X	DoIO(&Iosr);
X	if (Iosr.IOSer.io_Actual > 0) {
X	    if (debug > 8)
X		printf("(r%d/%d)", n, Iosr.IOSer.io_Actual);
X	    XInIdx = 0;
X	    XInLen = Iosr.IOSer.io_Actual;
X	    goto top;
X	}
X    }
X
X    /*
X     *	no bytes ready, wait for one.
X     *
X     *	once every 3 seconds check carrier detect.
X     */
X
X    bytetimeout = byteto;
X    Iot0.tr_time.tv_secs = 3;
X    Iot0.tr_time.tv_micro= 0;
X    SendIO(&Iot0);
X
X    Iosr.IOSer.io_Command = CMD_READ;
X    Iosr.IOSer.io_Data = (APTR)XInBuf;
X    Iosr.IOSer.io_Length = 1;
X    Iosr.IOSer.io_Actual = 0;	/*  trying to find a bug... */
X    SendIO(&Iosr);
X
X    smask = 1L << Iosr.IOSer.io_Message.mn_ReplyPort->mp_SigBit;
X    tmask = 1L << Iot0.tr_node.io_Message.mn_ReplyPort->mp_SigBit;
X
X    for (;;) {
X	long mask = Wait(tmask | smask | SIGBREAKF_CTRL_C);
X
X	if (mask & SIGBREAKF_CTRL_C) {
X	    AbortIO(&Iosr);
X	    WaitIO(&Iosr);
X	    AbortIO(&Iot0);
X	    WaitIO(&Iot0);
X	    xexit(1);
X	}
X	if (CheckIO(&Iosr)) {
X	    WaitIO(&Iosr);
X	    AbortIO(&Iot0);
X	    WaitIO(&Iot0);
X
X	    ch = (int)XInBuf[0];
X
X	    if (debug > 8) {
X		if (debugRead == 0)
X		    printf("\nREAD ");
X		debugRead = 1;
X		printf("(waitc%d)", Iosr.IOSer.io_Actual);
X		printc(ch);
X	    }
X	    return(ch);
X	}
X	if (CheckIO(&Iot0)) {
X	    WaitIO(&Iot0);
X
X	    Iot0.tr_time.tv_secs = 3;
X	    Iot0.tr_time.tv_micro= 0;
X
X	    bytetimeout -= Iot0.tr_time.tv_secs;
X	    if (bytetimeout > 0) {
X		if (CheckCarrier() == 0) {
X		    AbortIO(&Iosr);
X		    WaitIO(&Iosr);
X		    break;
X		}
X		SendIO(&Iot0);
X	    } else {
X		AbortIO(&Iosr);
X		WaitIO(&Iosr);
X		if (Iosr.IOSer.io_Actual == 1)
X		    return((int)XInBuf[0]);
X		break;
X	    }
X	}
X    }
X    if (debug > 8)
X	printf("\nRecv-EOF\n");
X    return(EOF);
X}
X
Xxwrite(buf, ctr)
Xunsigned char *buf;
Xint ctr;
X{
X    return(xxwrite(buf, ctr, 0));
X}
X
Xxwritea(buf, ctr)
Xunsigned char *buf;
Xint ctr;
X{
X    xxwrite(buf, ctr, 1);
X    return(ctr);
X}
X
Xxxwrite(buf, ctr, async)
Xunsigned char *buf;
Xint ctr;
X{
X    if (debug > 8) {
X	short i;
X	if (debugRead)
X	    printf("\nWRITE ");
X	debugRead = 0;
X	for (i = 0; i < ctr; ++i) {
X	    printc(buf[i]);
X	}
X	printf("\n");
X    }
X    if (IoswIP) {
X	WaitIO(&Iosw);
X	IoswIP = 0;
X    }
X
X    Iosw.IOSer.io_Command = CMD_WRITE;
X    Iosw.IOSer.io_Length = ctr;
X    Iosw.IOSer.io_Data = (APTR) &buf[0];
X    if (async) {
X	SendIO(&Iosw);
X	IoswIP = 1;
X    } else {
X	DoIO(&Iosw);
X    }
X    return ctr;
X}
X
Xvoid
XSendBreak()
X{
X    Ioss.IOSer.io_Command = SDCMD_BREAK;
X    DoIO(&Ioss);
X}
X
XCheckCarrier()
X{
X    Ioss.IOSer.io_Command = SDCMD_QUERY;
X    DoIO(&Ioss);
X    if (IgnoreCD)
X	return(1);
X    if (Ioss.io_Status & CIAF_COMCD)    /*  non-zero == no carrier */
X	return(0);
X    return(1);
X}
X
Xvoid
Xbzero(s, cnt)
Xchar   *s;
Xint    cnt;
X{
X    int    i;
X    for (i = 0; i < cnt; i++) {
X	*s++ = '\0';
X    }
X}
X
Xvoid
Xbcopy(from, to, cnt)
Xchar   *from;
Xchar   *to;
Xint    cnt;
X{
X    int    i;
X    for (i = 0; i < cnt; i++) {
X	*to++ = *from++;
X    }
X}
X
X/*
X * Transform a filename from a uucp packet (in Unix format) into a local
X * filename that will work in the local file system.
X */
X
Xvoid
Xmunge_filename(s, d)
Xchar *s, *d;
X{
X    if (*s != '~') {
X	if (s != d)
X	    strcpy(d, s);
X	return;
X    }
X
X    /*
X     *	~/ ...	convert to UUPUB:
X     *	~user/...   convert to <homedir>/...
X     */
X
X    {
X	short i;
X	short c;
X	char *t;
X	struct passwd *pw;
X
X	for (i = 1; s[i] && s[i] != '/'; ++i);
X	c = s[i];
X
X	s[i] = 0;
X	if (i == 1)
X	    pw = NULL;
X	else
X	    pw = getpwnam(s + 1);
X	s[i] = c;
X
X	if (c == '/')
X	    ++i;
X
X	if (pw) {
X	    t = malloc(strlen(pw->pw_dir) + strlen(s + i) + 1);
X	    strcpy(t, pw->pw_dir);
X	} else {
X	    t = malloc(strlen(s + i) + 32);
X	    strcpy(t, "UUPUB:");
X	}
X	strcat(t, s + i);
X	strcpy(d, t);
X	free(t);
X    }
X}
X
Xhangup()
X{
X    reset_modem();
X
X    if (Execute("run >nil: <nil: uuxqt", NULL, NULL) == 0) {
X	if (Execute("run >nil: <nil: uucp:c/uuxqt", NULL, NULL) == 0)
X	    puts("Unable to run UUXQT");
X    }
X    return SUCCESS;
X}
X
Xstatic char names[3000];
Xstatic char *pointers[300];
Xstatic int file_pointer;
X
Xchar *
Xwork_scan(system_name)
Xchar *system_name;
X{
X    static char name[128];
X    int count;
X
X    file_pointer = 0;
X
X    if (strlen(system_name) > 7) {
X	system_name[7] = '\0';
X    }
X
X    sprintf(name,"UUSPOOL:C.%s#?", system_name);
X
X    if (debug > 2)
X	printf("Looking for %s\n",name);
X
X    count = getfnl(name,names,sizeof(names),0);
X
X    if (count > 0) {
X	if (strbpl(pointers,300,names) != count) {
X	    printf("Too many command files for %s.\n",system_name);
X	    return (char *)NULL;
X	}
X    } else {
X	return (char *)NULL;
X    }
X    if (debug > 2)
X	printf("Found -> %s\n", pointers[file_pointer]);
X    return (char *)1;
X}
X
Xchar *
Xwork_next(system_name)
Xchar *system_name;
X{
X    if (debug > 2)
X	printf("Found -> %s\n", pointers[file_pointer]);
X    return pointers[file_pointer++];
X}
X
X/*
X *  Closing and openning the serial device drops DTR
X */
X
Xvoid
Xamiga_closeopen(str)
Xchar *str;
X{
X    CloseSerial();
X    Delay(60);
X    OpenSerial();
X}
X
Xvoid
Xamiga_setup()
X{
X    mountrequest(0);        /*  disallow requesters */
X
X    OpenSerial();
X
X    if (OpenDevice(TIMERNAME, UNIT_VBLANK, &Iot0, 0))  {
X	Iot0.tr_node.io_Device = NULL;
X	printf("Can't open timer device.");
X	xexit(1);
X    }
X
X    Iot0.tr_node.io_Message.mn_ReplyPort = CreatePort("UUCICO-Timer", 0L);
X    Iot0.tr_node.io_Command = TR_ADDREQUEST;
X    Iot0.tr_node.io_Error = 0;
X
X    {
X	struct Task *task = (struct Task *)FindTask(NULL);
X	OldTaskName = task->tc_Node.ln_Name;
X	task->tc_Node.ln_Name = "uucico";
X    }
X}
X
Xvoid
Xset_baud(baud)
Xint baud;
X{
X    Iosr.IOSer.io_Command = SDCMD_SETPARAMS;
X    Iosr.io_SerFlags =	SERF_SHARED | SERF_XDISABLED;
X    Iosr.io_Baud = baud;
X    Iosr.io_ReadLen = 8L;
X    Iosr.io_WriteLen = 8L;
X    Iosr.io_CtlChar = 0x11130000L;
X    Iosr.io_RBufLen = 4096;
X
X    DoIO(&Iosr);
X}
X
Xvoid
XOpenSerial()
X{
X    Iosr.io_SerFlags = SERF_SHARED | SERF_XDISABLED;
X    Iosr.IOSer.io_Message.mn_ReplyPort = CreatePort("Read_RS",0);
X
X    if (OpenDevice(DeviceName, DeviceUnit, &Iosr, NULL)) {
X	Iosr.IOSer.io_Device = NULL;
X	printf("Can not open serial port for read.\n");
X	xexit(TRUE);
X    }
X
X    /*
X     *	Assume a Getty is running, if the opencount is > 2 then
X     *	assume collision and disallow
X     */
X
X    if (Iosr.IOSer.io_Device->dd_Library.lib_OpenCnt > 2) {
X	CloseDevice(&Iosr);
X	Iosr.IOSer.io_Device = NULL;
X	printf("Collision, serial port in use!\n");
X	xexit(TRUE);
X    }
X
X    /*
X     *	The public port 'Lock-<spname>-<unit>' is used to lock the
X     *	serial port (Getty will lock it this way while it is
X     *	receiving an incomming call so if we are Getty assume it
X     *	is already locked)
X     */
X
X    if (Getty == 0)
X	LockSerialPort(DeviceName, DeviceUnit);
X
X    Iosw = Iosr;
X    Iosw.IOSer.io_Message.mn_ReplyPort = CreatePort("Write_RS", 0);
X    Ioss = Iosw;
X
X    Iosr.IOSer.io_Command = SDCMD_QUERY;
X    DoIO(&Iosr);
X
X    set_baud(Iosr.io_Baud);
X}
X
Xvoid
XCloseSerial()
X{
X    if (IoswIP) {
X	WaitIO(&Iosw);
X	IoswIP = 0;
X    }
X    if (Iosr.IOSer.io_Device) {
X	CloseDevice(&Iosr);
X	Iosr.IOSer.io_Device = NULL;
X	if (Getty == 0)
X	    UnLockSerialPort(DeviceName, DeviceUnit);
X    }
X    if (Iosr.IOSer.io_Message.mn_ReplyPort) {
X	DeletePort(Iosr.IOSer.io_Message.mn_ReplyPort);
X	Iosr.IOSer.io_Message.mn_ReplyPort = NULL;
X    }
X    if (Iosw.IOSer.io_Message.mn_ReplyPort) {
X	DeletePort(Iosw.IOSer.io_Message.mn_ReplyPort);
X	Iosw.IOSer.io_Message.mn_ReplyPort = NULL;
X    }
X}
X
Xvoid
Xxexit(code)
X{
X    ++InExitRoutine;
X
X    if (InExitRoutine == 1 && code && Iosr.IOSer.io_Device && CheckCarrier())
X	reset_modem();
X
X    CloseSerial();
X
X    {
X	struct Task *task = (struct Task *)FindTask(NULL);
X	if (OldTaskName)
X	    task->tc_Node.ln_Name = OldTaskName;
X    }
X
X    if (Iot0.tr_node.io_Device) {
X	CloseDevice(&Iot0);
X	Iot0.tr_node.io_Device = NULL;
X    }
X    if (Iot0.tr_node.io_Message.mn_ReplyPort) {
X	DeletePort(Iot0.tr_node.io_Message.mn_ReplyPort);
X	Iot0.tr_node.io_Message.mn_ReplyPort = NULL;
X    }
X    chdir(path);
X    if (code)
X	printf("\nAbnormal Termination.\n");
X
X    mountrequest(1);
X
X    UnLockFiles();      /*  unlock any hanging locks */
X
X    exit(code);
X}
X
Xvoid
Xprintc(c)
Xunsigned char c;
X{
X    c &= 0x7F;
X
X    if (c < 32)
X	printf("^%c", c | 0x40);
X    else if (c == 32)
X	printf("_");
X    else if (c < 128)
X	printf("%c", c);
X    else
X	printf("(%02x)", c);
X}
X
END_OF_FILE
if test 11298 -ne `wc -c <'src/uucico/sysdep.c'`; then
    echo shar: \"'src/uucico/sysdep.c'\" unpacked with wrong size!
fi
# end of 'src/uucico/sysdep.c'
fi
if test -f 'src/uuser/uuser.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/uuser/uuser.c'\"
else
echo shar: Extracting \"'src/uuser/uuser.c'\" \(13243 characters\)
sed "s/^X//" >'src/uuser/uuser.c' <<'END_OF_FILE'
X
X/*
X *  UUSER.C UUSER:devicename/unitnumber/options
X *	    UUSER:serial.device/0/R1000
X *
X *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
X *
X *  options:
X *	Rn	Set read timeout when no data available to n millisecs
X *	C0	Ignore carrier detect
X *
X *  features:
X *	1K asynchronous write capability (write 0 bytes to sync up)
X *	programmable read-timeout (Getty starts procs up w/ 1sec to)
X *
X *	combined together, you can easily implement 100% efficient
X *	protocols even with that 1 second read timeout!
X */
X
X#include <exec/types.h>
X#include <exec/memory.h>
X#include <devices/serial.h>
X#include <devices/timer.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X#include <libraries/filehandler.h>
X#include <hardware/cia.h>
X#include <proto/all.h>
X
X#define WRITEBUFSIZE	1024
X#define MPC (MEMF_PUBLIC|MEMF_CLEAR)        /* options to AllocMem()    */
X
X#define BTOC(x, type)   ((type *)((long)x << 2))
X#define CTOB(x)         ((BPTR)((long)x >> 2))
X
X#define DOS_FALSE    0
X#define DOS_TRUE     -1
X
Xtypedef struct IOExtSer     IOS;
Xtypedef struct timerequest  IOT;
Xtypedef struct IORequest    IOR;
Xtypedef struct timeval	    TimeVal;
X
Xtypedef struct FileLock     LOCK;
Xtypedef struct DosPacket    Packet;
Xtypedef struct Process	    PROC;
Xtypedef struct DeviceNode   DEVNODE;
Xtypedef struct FileHandle   FH;
Xtypedef struct Message	    MSG;
Xtypedef struct Node	    NODE;
Xtypedef struct List	    LIST;
Xtypedef struct MsgPort	    PORT;
X
Xtypedef struct SHandle {
X    NODE    Node;
X    IOT     Iot;		/* wait-for-char and read req	*/
X    IOS     Ios;
X    IOS     Iosr;		/* 1005 			*/
X    IOS     Iosw;		/* 1005,1006			*/
X    char    IotIP;
X    char    IosrIP;
X    char    IoswIP;
X    char    RxIn[1];		/* one char buffer		*/
X    char    *TxOut;		/* asynch write buffer		*/
X    Packet  *RPacket;		/* current pending read packet	*/
X    Packet  *WPacket;		/* current pending write packet */
X    short   Flags;
X    LIST    RxWait;		/* requests waiting for data	*/
X    LIST    TxWait;		/* requests waiting to write	*/
X    LIST    CxWait;		/* wait for char		*/
X    TimeVal ReadTo;
X} SHandle;
X
X#define HF_IGNORECD	0x01
X#define HF_CDLOST	0x02
X#define HF_RTO		0x04
X#define HF_DONTLOCK	0x08	/* if G option for from-getty	*/
X
Xextern Packet *taskwait();   /* wait for a message           */
X
Xlong SysBase;			/* required to make Exec calls	*/
Xchar ScrBuf[256];		/* Scratch buffer		*/
XPORT *IoSink;
XLIST HanList;
XLIST NodList;
XIOT  Iot;			/* Iot master, also used for CD */
Xchar IotIP;
X
Xvoid	AttemptRead();
Xvoid	AttemptWrite();
Xvoid	AbortPackets();
Xvoid	StartTimer();
X
X__saveds void
X_dummy()
X{
X    PROC	*myproc;
X    DEVNODE	*mynode;
X    UBYTE	notdone;
X    long	mask;
X
X    SysBase = *(long *)4;
X    IoSink = CreatePort(NULL, 0);
X    NewList(&HanList);
X    NewList(&NodList);
X
X    Iot.tr_node.io_Message.mn_ReplyPort = IoSink;
X    OpenDevice("timer.device", UNIT_VBLANK, &Iot, 0);
X    Iot.tr_node.io_Command = TR_ADDREQUEST;
X    Iot.tr_time.tv_secs = 4;
X    Iot.tr_time.tv_micro= 0;
X    SendIO(&Iot);
X    IotIP = 1;
X
X    myproc  = (PROC *)FindTask(0L);
X
X    /*
X     * INITIAL STARTUP MESSAGE
X     */
X
X    {
X	Packet *mypkt;
X
X	mypkt	= taskwait(myproc);
X	mynode	= BTOC(mypkt->dp_Arg3, DEVNODE);
X	mynode->dn_Task = &myproc->pr_MsgPort;
X	returnpkt(mypkt, myproc, DOS_TRUE, 0);
X    }
X
Xloop:
X    notdone = 1;
X    mask = (1 << IoSink->mp_SigBit) | (1 << myproc->pr_MsgPort.mp_SigBit);
X    while (notdone) {
X	Packet *mypkt;		 /* dos packet received      */
X	IOR *ior;
X	SHandle *handle;
X	long type;		    /* type of packet		*/
X
X	ior = (IOR *)GetMsg(IoSink);
X	mypkt = (Packet *)GetMsg(&myproc->pr_MsgPort);
X	if (mypkt)
X	    mypkt = (Packet *)(((MSG *)mypkt)->mn_Node.ln_Name);
X	while (mypkt == NULL && ior == NULL) {
X	    Wait(mask);
X	    ior = (IOR *)GetMsg(IoSink);
X	    mypkt = (Packet *)GetMsg(&myproc->pr_MsgPort);
X	    if (mypkt)
X		mypkt = (Packet *)(((MSG *)mypkt)->mn_Node.ln_Name);
X	}
X
X	/*
X	 *  Make sure there is at least one free node in node list
X	 */
X
X	if (NodList.lh_Head == (NODE *)&NodList.lh_Tail) {
X	    NODE *pknode = AllocMem(sizeof(NODE), MPC);
X	    AddTail(&NodList, pknode);
X	}
X
X	/*
X	 *  Returned IO request, sift through lists to find it.
X	 */
X
X	if (ior) {
X	    if (ior == &Iot) {      /*  Check for carrier lost */
X		for (handle = (SHandle *)HanList.lh_Head; handle != (SHandle *)&HanList.lh_Tail; handle = (SHandle *)handle->Node.ln_Succ) {
X		    if (!(handle->Flags & HF_IGNORECD) && !(handle->Flags & HF_CDLOST)) {
X			handle->Ios.IOSer.io_Command = SDCMD_QUERY;
X			DoIO(&handle->Ios);
X			if (handle->Ios.io_Status & CIAF_COMCD) {
X			    handle->Flags |= HF_CDLOST;
X			    AbortPackets(handle, myproc);
X			}
X		    }
X		}
X		if (HanList.lh_Head == (NODE *)&HanList.lh_Tail) {
X		    IotIP = 0;
X		} else {
X		    Iot.tr_time.tv_secs = 4;
X		    Iot.tr_time.tv_micro= 0;
X		    SendIO(&Iot);
X		    IotIP = 1;
X		}
X	    } else
X	    for (handle = (SHandle *)HanList.lh_Head; handle != (SHandle *)&HanList.lh_Tail; handle = (SHandle *)handle->Node.ln_Succ) {
X		if (ior == (IOR *)&handle->Iosr) {
X		    returnpkt(handle->RPacket, myproc, handle->Iosr.IOSer.io_Actual, 0);
X		    handle->IosrIP = 0;
X		    handle->RPacket = NULL;
X
X		    if (handle->IotIP) {
X			AbortIO(&handle->Iot);
X			WaitIO(&handle->Iot);
X			handle->IotIP = 0;
X		    }
X		    AttemptRead(handle, myproc);
X		}
X		if (ior == (IOR *)&handle->Iosw) {
X		    handle->IoswIP = 0;
X		    if (handle->WPacket) {
X			handle->Iosw.IOSer.io_Data = (APTR)handle->TxOut;
X			handle->Iosw.IOSer.io_Length= handle->WPacket->dp_Arg3 - handle->WPacket->dp_Res1;
X			SendIO(&handle->Iosw);
X			handle->IoswIP = 1;
X			handle->WPacket->dp_Res1 = handle->WPacket->dp_Arg3;
X			returnpktplain(handle->WPacket, myproc);
X			handle->WPacket = NULL;
X		    } else {
X			AttemptWrite(handle, myproc);
X		    }
X		}
X		if (ior == (IOR *)&handle->Iot) {
X		    handle->IotIP = 0;
X		    if ((handle->Flags & HF_RTO) && handle->IosrIP) {
X			AbortIO(&handle->Iosr);
X		    }
X		}
X	    }
X	}
X
X	if (mypkt) {
X	    mypkt->dp_Res1 = DOS_TRUE;	/* default return value     */
X	    mypkt->dp_Res2 = 0; 	/* default no error	    */
X	    type = mypkt->dp_Type;	/* packet type		    */
X
X	    /*
X	     *	Extract pipe pointer (only applies to read/write)
X	     */
X
X	    handle = (SHandle *)mypkt->dp_Arg1;     /*  READ/WRITE only */
X
X	    switch(type) {
X	    case ACTION_FINDINPUT:
X	    case ACTION_FINDOUTPUT:
X	    case ACTION_FINDUPDATE:
X		if (IotIP == 0)
X		    StartTimer(4);
X		{
X		    FH	 *fh = BTOC(mypkt->dp_Arg1, FH);
X		    char *path = BTOC(mypkt->dp_Arg3, char);
X		    char *unit;
X		    long n;
X
X		    movmem(path + 1, ScrBuf, *path);
X		    ScrBuf[*path] = 0;
X		    path = ScrBuf;
X
X		    handle = AllocMem(sizeof(SHandle), MPC);
X
X		    if (strcmp(ScrBuf, "*") == 0)
X			strcpy(ScrBuf, "serial.device/0");
X		    for (unit = path; *unit && *unit != '/'; ++unit) {
X			if (*unit == ':')
X			    path = unit + 1;
X		    }
X		    if (*unit == '/') {
X			char *opts;
X
X			*unit = 0;
X			++unit;
X			for (opts = unit; *opts && *opts != '/'; ++opts);
X			while (*opts) {
X			    n = atoi(opts + 1);
X			    switch(*opts) {
X			    case '/':
X				break;
X			    case 'R':
X				handle->ReadTo.tv_secs = n / 1000;
X				handle->ReadTo.tv_micro= (n % 1000) * 1000;
X				handle->Flags |= HF_RTO;
X				break;
X			    case 'C':
X				handle->Flags |= HF_IGNORECD;
X				break;
X			    case 'G':
X				if (n)
X				    handle->Flags |= HF_DONTLOCK;
X				break;
X			    }
X			    ++opts;
X			}
X		    }
X
X		    /* proc = (PROC *)mypkt->dp_Port->mp_SigTask; */
X
X		    /*
X		     * Open the device
X		     */
X
X		    handle->Ios.IOSer.io_Message.mn_ReplyPort = IoSink;
X		    handle->Ios.io_SerFlags = SERF_XDISABLED | SERF_RAD_BOOGIE | SERF_SHARED;
X		    if (OpenDevice(path, atoi(unit), &handle->Ios, 0)) {
X			FreeMem(handle, sizeof(SHandle));
X			mypkt->dp_Res1 = DOS_FALSE;
X			mypkt->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
X			returnpktplain(mypkt, myproc);
X			break;
X		    }
X		    fh->fh_Arg1 = (long)handle;
X		    fh->fh_Port = (struct MsgPort *)DOS_TRUE;
X
X		    handle->Iosr = handle->Ios;
X		    handle->Iosw = handle->Ios;
X		    handle->Iosr.IOSer.io_Command = CMD_READ;
X		    handle->Iosw.IOSer.io_Command = CMD_WRITE;
X		    handle->Iot = Iot;
X		    NewList(&handle->RxWait);
X		    NewList(&handle->TxWait);
X		    NewList(&handle->CxWait);
X		    AddTail(&HanList, handle);
X		    returnpktplain(mypkt, myproc);
X		}
X		break;
X	    case ACTION_END:
X		Remove(handle);
X		if (handle->IosrIP) {
X		    AbortIO(&handle->Iosr);
X		    WaitIO(&handle->Iosr);
X		}
X		if (handle->IoswIP) {
X		    WaitIO(&handle->Iosw);
X		}
X		if (handle->IotIP) {
X		    AbortIO(&handle->Iot);
X		    WaitIO(&handle->Iot);
X		}
X		AbortPackets(handle, myproc);
X		CloseDevice(&handle->Ios);
X		returnpktplain(mypkt, myproc);
X		if (handle->TxOut)
X		    FreeMem(handle->TxOut, WRITEBUFSIZE);
X		FreeMem(handle, sizeof(SHandle));
X		break;
X	    case ACTION_READ:
X		{
X		    NODE *pknode = RemHead(&NodList);
X		    mypkt->dp_Res1 = 0;
X		    pknode->ln_Name = (char *)mypkt;
X		    AddTail(&handle->RxWait, pknode);
X		    AttemptRead(handle, myproc);
X		}
X		break;
X	    case ACTION_WRITE:
X		{
X		    NODE *pknode = RemHead(&NodList);
X		    mypkt->dp_Res1 = 0;
X		    pknode->ln_Name = (char *)mypkt;
X		    AddTail(&handle->TxWait, pknode);
X		    AttemptWrite(handle, myproc);
X		}
X		break;
X	    case ACTION_WAIT_CHAR:
X	    default:
X		returnpkt(mypkt, myproc, DOS_FALSE, ERROR_ACTION_NOT_KNOWN);
X		break;
X	    }
X	}
X    }
X
X    /*
X     *	Can only exit if no messages pending.  There might be a window
X     *	here, but there is nothing that can be done about it.
X     */
X
X    Forbid();
X    if (taskpktrdy(myproc)) {
X	Permit();
X	goto loop;
X    }
X    mynode->dn_Task = FALSE;
X    Permit();
X
X    if (IotIP) {
X	AbortIO(&Iot);
X	WaitIO(&Iot);
X    }
X    CloseDevice(&Iot);
X
X    /* we are a process "so we fall off the end of the world" */
X    /* MUST fall through */
X}
X
Xvoid
XAttemptRead(handle, myproc)
XSHandle *handle;
XPROC *myproc;
X{
X    Packet *mypkt;
X    NODE *pknode;
X
X    if (handle->Flags & HF_CDLOST) {
X	AbortPackets(handle, myproc);
X	return;
X    }
Xloop:
X    if (handle->IosrIP == 0 && (pknode = RemHead(&handle->RxWait))) {
X	long n;
X
X	AddTail(&NodList, pknode);
X
X	mypkt = (Packet *)pknode->ln_Name;
X
X	/*
X	 *  special case.  If you read 0 bytes, 0 is returned if data
X	 *  is pending, else -1, and NO timeout occurs.
X	 */
X
X	handle->Ios.IOSer.io_Command = SDCMD_QUERY;
X	DoIO(&handle->Ios);
X
X	if (mypkt->dp_Arg3 == 0) {
X	    if (handle->Ios.IOSer.io_Actual > 0)
X		returnpkt(mypkt, myproc, 0, 0);     /* 0=data rdy */
X	    else
X		returnpkt(mypkt, myproc, -1, 0);    /* -1=data not rdy */
X	    goto loop;
X	}
X
X	if ((n = handle->Ios.IOSer.io_Actual) > 0) {
X	    if (n > mypkt->dp_Arg3)
X		n = mypkt->dp_Arg3;
X	    handle->Iosr.IOSer.io_Data = (APTR)mypkt->dp_Arg2;
X	    handle->Iosr.IOSer.io_Length = n;
X	    DoIO(&handle->Iosr);
X	    mypkt->dp_Res1 = handle->Iosr.IOSer.io_Actual;
X	    returnpktplain(mypkt, myproc);
X	    goto loop;
X	}
X	handle->Iosr.IOSer.io_Data = (APTR)mypkt->dp_Arg2;
X	handle->Iosr.IOSer.io_Length = 1;
X	SendIO(&handle->Iosr);
X	handle->IosrIP = 1;
X	handle->RPacket = mypkt;
X
X	if (handle->Flags & HF_RTO) {
X	    if (handle->IotIP) {
X		AbortIO(&handle->Iot);
X		WaitIO(&handle->Iot);
X	    }
X	    handle->Iot.tr_time = handle->ReadTo;
X	    SendIO(&handle->Iot);
X	    handle->IotIP = 1;
X	}
X    }
X}
X
Xvoid
XAttemptWrite(handle, myproc)
XSHandle *handle;
XPROC *myproc;
X{
X    Packet *mypkt;
X    NODE *pknode;
X
X    if (handle->Flags & HF_CDLOST) {
X	AbortPackets(handle, myproc);
X	return;
X    }
X    if (handle->IoswIP == 0 && (pknode = RemHead(&handle->TxWait))) {
X	AddTail(&NodList, pknode);
X
X	mypkt = (Packet *)pknode->ln_Name;
X
X	if (handle->TxOut == NULL)
X	    handle->TxOut = AllocMem(WRITEBUFSIZE, MPC);
X
X	if (mypkt->dp_Arg3 <= WRITEBUFSIZE) {   /* fully asynch */
X	    movmem((char *)mypkt->dp_Arg2, handle->TxOut, mypkt->dp_Arg3);
X	    handle->Iosw.IOSer.io_Data = (APTR)handle->TxOut;
X	    handle->Iosw.IOSer.io_Length = mypkt->dp_Arg3;
X	    SendIO(&handle->Iosw);
X	    mypkt->dp_Res1 = mypkt->dp_Arg3;
X	    returnpktplain(mypkt, myproc);
X	    handle->WPacket = NULL;
X	} else {				/*  semi-asynch */
X	    long n = mypkt->dp_Arg3 - WRITEBUFSIZE;
X	    handle->Iosw.IOSer.io_Data = (APTR)mypkt->dp_Arg2;
X	    handle->Iosw.IOSer.io_Length = n;
X	    SendIO(&handle->Iosw);
X	    movmem((char *)mypkt->dp_Arg2 + n, handle->TxOut, WRITEBUFSIZE);
X	    mypkt->dp_Res1 += n;
X	    handle->WPacket = mypkt;
X	}
X	handle->IoswIP = 1;
X    }
X}
X
Xvoid
XAbortPackets(handle, myproc)
XSHandle *handle;
X{
X    NODE *pknode;
X    Packet *mypkt;
X
X    if (handle->RPacket)
X	returnpktplain(handle->RPacket, myproc);
X    if (handle->WPacket)
X	returnpktplain(handle->RPacket, myproc);
X
X    handle->RPacket = NULL;
X    handle->WPacket = NULL;
X
X    while (pknode = RemHead(&handle->RxWait)) {
X	mypkt = (Packet *)pknode->ln_Name;
X	if (mypkt->dp_Arg3 == 0)
X	    mypkt->dp_Res1 = 0;     /* for poll, return data rdy */
X	else
X	    mypkt->dp_Res1 = -1;
X	returnpktplain(mypkt, myproc);
X	AddTail(&NodList, pknode);
X    }
X
X    while (pknode = RemHead(&handle->TxWait)) {
X	mypkt = (Packet *)pknode->ln_Name;
X	mypkt->dp_Res1 = -1;
X	returnpktplain(mypkt, myproc);
X	AddTail(&NodList, pknode);
X    }
X}
X
Xvoid
XStartTimer(secs)
X{
X    if (IotIP) {
X	AbortIO(&Iot);
X	WaitIO(&Iot);
X    }
X    Iot.tr_time.tv_secs = secs;
X    Iot.tr_time.tv_micro= 0;
X    SendIO(&Iot);
X    IotIP = 1;
X}
X
X
END_OF_FILE
if test 13243 -ne `wc -c <'src/uuser/uuser.c'`; then
    echo shar: \"'src/uuser/uuser.c'\" unpacked with wrong size!
fi
# end of 'src/uuser/uuser.c'
fi
echo shar: End of archive 7 \(of 16\).
cp /dev/null ark7isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 16 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
-- 
Submissions to comp.sources.amiga and comp.binaries.amiga should be sent to:
	amiga@cs.odu.edu	
or	amiga@xanth.cs.odu.edu	( obsolescent mailers may need this address )
or	...!uunet!xanth!amiga	( very obsolescent mailers need this address )

Comments, questions, and suggestions should be addressed to ``amiga-request''
(please only use ``amiga'' for actual submissions) at the above addresses.