fyi> popme version 0.04 (simple pop3 client) (1/3)

2 views
Skip to first unread message

Robin A. Goodfellow

unread,
Oct 10, 1997, 3:00:00 AM10/10/97
to

Submitted-by: r...@earthling.net
Archive-name: popme-0.04/part01

---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is popme-0.04, a shell archive (produced by GNU shar 4.1)
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1997-10-10 10:31 MET DST by <r...@earthling.net>.
# Source directory was `/home/earthlings/rag/src/popme-0.04'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 2135 -rw-r--r-- popme-0.04/Makefile
# 17982 -rw-r--r-- popme-0.04/COPYING
# 5441 -rw-r--r-- popme-0.04/README
# 416 -rw-r--r-- popme-0.04/THANKS
# 19370 -rw-r--r-- popme-0.04/getopt.c
# 3476 -rw-r--r-- popme-0.04/getopt1.c
# 4333 -rw-r--r-- popme-0.04/getopt.h
# 3767 -rw-r--r-- popme-0.04/net.c
# 2806 -rw-r--r-- popme-0.04/socks.c
# 12410 -rw-r--r-- popme-0.04/popme.c
# 2880 -rw-r--r-- popme-0.04/popme.h
# 6232 -rw-r--r-- popme-0.04/popme.1
# 5660 -rw-r--r-- popme-0.04/popme.man
# 13942 -rw-r--r-- popme-0.04/popme.ps
# 4602 -rw-r--r-- popme-0.04/orig/pop3-miniclient.tar.gz
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
shar_touch=touch
else
shar_touch=:
echo 'WARNING: not restoring timestamps'
fi
rm -f 1231235999 $$.touch
#
# ============= popme-0.04/Makefile ==============
if test ! -d 'popme-0.04'; then
echo 'x - creating directory popme-0.04'
mkdir 'popme-0.04'
fi
if test -f 'popme-0.04/Makefile' && test X"$1" != X"-c"; then
echo 'x - skipping popme-0.04/Makefile (File already exists)'
else
echo 'x - extracting popme-0.04/Makefile (text)'
sed 's/^X//' << 'United Earthlings, Inc.' > 'popme-0.04/Makefile' &&
# $Id: Makefile,v 1.283 1997/10/10 08:19:57 goodfellow Rel $
X
SHELL = /bin/sh
X
PRODUCT = popme
VERSION = 0.04
SPECS = "A simple mail client for post office protocol version 3"
X
CC = cc
CFLAGS = -g -I. -DDEBUG=1
CC = gcc
CFLAGS = -O -I.
X
$(PRODUCT): config.h getopt.o getopt1.o socks.o net.o $(PRODUCT).o
X $(CC) $(CFLAGS) -o $(PRODUCT) getopt.o getopt1.o socks.o net.o $(PRODUCT).o
X
config.h: Makefile
X @echo "/* config.h -- created from Makefile [DO NOT EDIT!] */" >config.h
X @echo "#define PRODUCT \"$(PRODUCT)\"" >>config.h
X @echo "#define VERSION \"$(VERSION)\"" >>config.h
X @echo "#define SPECS \"$(SPECS)\"" >>config.h
X
version.n: Makefile
X @echo ".ds ED Edition $(VERSION)" > version.n
X @echo ".ds UP `date '+%B %Y'`" >> version.n
X @echo ".ds VE $(VERSION)" >> version.n
X
popme.o: config.h popme.c popme.h
popme.1: version.n
popme.man: popme.1
popme.ps: popme.1
X
man: version.n popme.1
X nroff -man popme.1 >popme.man
X groff -man popme.1 >popme.ps
readme: version.n
X @echo "Popme README file for version $(VERSION)" >README
X @echo "Popme has originally been written by some else." >> README
X @echo "" >> README
X groff -man -Tascii popme.1 | ul -t dumb | uniq >>README
X
DISTFILES = Makefile COPYING README THANKS getopt.c getopt1.c getopt.h \
X net.c socks.c popme.c popme.h popme.1 popme.man popme.ps
DISTNAME = popme-$(VERSION)
X
links: readme man
X rm -rf $(DISTNAME)
X mkdir $(DISTNAME)
X chmod 777 $(DISTNAME)
X @echo "Copying distribution files"
X for i in $(DISTFILES) ; do \
X ln ./$$i $(DISTNAME) 2> /dev/null || cp -p $$i $(DISTNAME); \
X done
X mkdir $(DISTNAME)/orig
X cp -p orig/pop3-miniclient.tar.gz $(DISTNAME)/orig
X chmod -R a+r $(DISTNAME)
X
dist tar: links
X rm -f $(DISTNAME).tar.*
X tar chovf $(DISTNAME).tar $(DISTNAME)
X gzip -v9 $(DISTNAME).tar
X rm -rf $(DISTNAME)
X
uue: dist
X uuencode $(DISTNAME).tar.gz $(DISTNAME).tar.gz >$(DISTNAME).uue
X
shar: links
X shar -c -n "$(DISTNAME)" -a -M \
X -s r...@earthling.net \
X -l50 -d "United Earthlings, Inc." -o "$(DISTNAME).shar" \
X $(DISTNAME)
X rm -rf $(DISTNAME)
X
clean:
X rm -f *~ core *.o config.h version.n popme.ps popme.man
realclean: clean
X rm -f popme *.tar.* *.shar.*
United Earthlings, Inc.
$shar_touch -am 1010102397 'popme-0.04/Makefile' &&
chmod 0644 'popme-0.04/Makefile' ||
echo 'restore of popme-0.04/Makefile failed'
shar_count="`wc -c < 'popme-0.04/Makefile'`"
test 2135 -eq "$shar_count" ||
echo "popme-0.04/Makefile: original size 2135, current size $shar_count"
fi
# ============= popme-0.04/COPYING ==============
if test -f 'popme-0.04/COPYING' && test X"$1" != X"-c"; then
echo 'x - skipping popme-0.04/COPYING (File already exists)'
else
echo 'x - extracting popme-0.04/COPYING (text)'
sed 's/^X//' << 'United Earthlings, Inc.' > 'popme-0.04/COPYING' &&
X GNU GENERAL PUBLIC LICENSE
X Version 2, June 1991
X
X Copyright (C) 1989, 1991 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 licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
X
X When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
X
X To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
X
X For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
X
X We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
X
X Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
X
X Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
X
X The precise terms and conditions for copying, distribution and
modification follow.
X
X GNU GENERAL PUBLIC LICENSE
X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
X
X 0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
X
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
X
X 1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
X
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
X
X 2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
X
X a) You must cause the modified files to carry prominent notices
X stating that you changed the files and the date of any change.
X
X b) You must cause any work that you distribute or publish, that in
X whole or in part contains or is derived from the Program or any
X part thereof, to be licensed as a whole at no charge to all third
X parties under the terms of this License.
X
X c) If the modified program normally reads commands interactively
X when run, you must cause it, when started running for such
X interactive use in the most ordinary way, to print or display an
X announcement including an appropriate copyright notice and a
X notice that there is no warranty (or else, saying that you provide
X a warranty) and that users may redistribute the program under
X these conditions, and telling the user how to view a copy of this
X License. (Exception: if the Program itself is interactive but
X does not normally print such an announcement, your work based on
X the Program is not required to print an announcement.)
X
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
X
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
X
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
X
X 3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
X
X a) Accompany it with the complete corresponding machine-readable
X source code, which must be distributed under the terms of Sections
X 1 and 2 above on a medium customarily used for software interchange; or,
X
X b) Accompany it with a written offer, valid for at least three
X years, to give any third party, for a charge no more than your
X cost of physically performing source distribution, a complete
X machine-readable copy of the corresponding source code, to be
X distributed under the terms of Sections 1 and 2 above on a medium
X customarily used for software interchange; or,
X
X c) Accompany it with the information you received as to the offer
X to distribute corresponding source code. (This alternative is
X allowed only for noncommercial distribution and only if you
X received the program in object code or executable form with such
X an offer, in accord with Subsection b above.)
X
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
X
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
X
X 4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
X
X 5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
X
X 6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
X
X 7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
X
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
X
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
X
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
X
X 8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
X
X 9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
X
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
X
X 10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
X
X NO WARRANTY
X
X 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
X
X 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
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
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
X
X To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
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 2 of the License, or
X (at your option) 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
Also add information on how to contact you by electronic and paper mail.
X
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
X
X Gnomovision version 69, Copyright (C) 19yy 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
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
X
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
X
X Yoyodyne, Inc., hereby disclaims all copyright interest in the program
X `Gnomovision' (which makes passes at compilers) written by James Hacker.
X
X <signature of Ty Coon>, 1 April 1989
X Ty Coon, President of Vice
X
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
United Earthlings, Inc.
$shar_touch -am 0928175997 'popme-0.04/COPYING' &&
chmod 0644 'popme-0.04/COPYING' ||
echo 'restore of popme-0.04/COPYING failed'
shar_count="`wc -c < 'popme-0.04/COPYING'`"
test 17982 -eq "$shar_count" ||
echo "popme-0.04/COPYING: original size 17982, current size $shar_count"
fi
# ============= popme-0.04/README ==============
if test -f 'popme-0.04/README' && test X"$1" != X"-c"; then
echo 'x - skipping popme-0.04/README (File already exists)'
else
echo 'x - extracting popme-0.04/README (text)'
sed 's/^X//' << 'United Earthlings, Inc.' > 'popme-0.04/README' &&
Popme README file for version 0.04
Popme has originally been written by some else.
X
X
POPME(1) USER COMMANDS POPME(1)
X
NAME
X popme - simple mail client for post office protocol ver-
X sion 3
X
SYNOPSIS
X popme --server SERV --user USER --passwd PWD [options] ...
X
X The options are:
X `--port' or `-P', `--delete' or `-D', `--debug' or
X `-d', `--help' or `-h', `--output FILE' or `-o
X FILE', `--verbose' or `-v', `--version' or `-V',
X `--warranty' or `-W'.
X
DESCRIPTION
X Popme is a simple mail client for post office protocol
X version 3 mail servers. It lets you specify your POP3
X server, your POP3 account name, and your POP3 password to
X download your email messages. The mail can be left on the
X server, or maye be deleted whatever you choose. You can
X retrieve the full contents of all messages or only the top
X N lines. (CAVEAT: If you decide to download only the top N
X lines remember NOT to delete the messages; otherwise
X they're gone.) You may also alter the IP port used to
X connect to the POP3 server; in cases you use a "hidden"
X POP3 server or have to circumvent a firewall, or must use
X a proxy. You can also turn on the debugging and verbose
X options for educational purposes and see what popme is
X doing and how the POP3 protocol works.
X
OPTIONS
X popme recognizes the following options:
X
X -s, --server SERV
X to set the POP3 server SERV.
X
X -u, --user ID
X to set the POP3 user ID.
X
X -p, --passwd PWD
X to set the POP3 password PWD.
X
X -P, --port PORT
X to set the POP3 server port. Default is port 110,
X per RFC.
X
X -D, --delete
X to delete mail from server. Default is to keep
X mail.
X
X -T, --top LINES
X to get only the top LINES of mail.
X
Version 0.04 October 1997 1
X
POPME(1) USER COMMANDS POPME(1)
X
X -d, --debug
X to print debugging information, which may help you
X understand how POP3 works.
X
X -h, --help
X to print this information.
X
X -o, --output FILE
X to specify the output FILE. If you do not specify
X an output file, the program writes to stdout.
X
X -v, --verbose
X to print information about what is being done.
X
X -V, --version
X to print version and COPYRIGHT information.
X
X -W, --warranty
X to print WARRANTY information.
X
SEE ALSO
X elm(1), eudora(1), mh(1), netscape(1), pine(1), zmail(1).
X
EXAMPLES
X Show me my email:
X example% popme --server pop3.earthling.net --user
X rag --passwd foobar
X
X Show me my email and delete it from the server:
X example% popme -s pop3.earthling.net -u rag -p foo-
X bar -D
X
X Save my email in file "mbox" deleting it from the server:
X example% popme -s pop3.earthling.net -u rag -p foo-
X bar -D -o mbox
X
X Show me the top 5 lines (envelope headers excluded) of
X my email messages:
X example% popme -s pop3.earthling.net -u rag -p foo-
X bar -T 5
X
X Save my email in file "mbox" from a server using a non-
X standard port for POP3 delivery:
X example% popme -s pop3.earthling.net -u rag -p foo-
X bar -P 10110 -o mbox
X
X In cases when there is no email waiting for you popme will
X prompt you with:
X
X popme: Sorry, no fish.
X
X After you've sucessfully saved your email to an mbox file,
X you can process the mail using your favourite mailreader,
X like elm(1), pine(1), mh(1).
X
Version 0.04 October 1997 2
X
POPME(1) USER COMMANDS POPME(1)
X
X Process my email from "mbox" file using elm(1):
X example% elm -f mbox
X
BUGS
X Bugs? In my programs? Are you kidding??
X
AVAILABILITY
X Popme has been cross posted to USENET's alt.sources,
X comp.sources.unix and is consequently available from your
X local netnews archive.
X
AUTHOR
X Copyright (c) 1997 Robin A. Goodfellow. All rights
X reserved.
X Send bugs, comments, and all the usual fish to r...@earthling.net
X
WARRANTY
X This program is free software; you can redistribute it
X and/or modify it under the terms of the GNU General Public
X License as published by the Free Software Foundation;
X either version 2 of the License, or (at your option) any
X later version.
X
X This program is distributed in the hope that it will be
X useful, but WITHOUT ANY WARRANTY; without even the implied
X warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
X PURPOSE. See the GNU General Public License for more
X details.
X
X You should have received a copy of the GNU General Public
X License along with this program; if not, write to the Free
X Software Foundation, 59 Temple Place--Suite 330, Boston,
X MA 02111-1307, USA.
X
Version 0.04 October 1997 3
X
United Earthlings, Inc.
$shar_touch -am 1010103197 'popme-0.04/README' &&
chmod 0644 'popme-0.04/README' ||
echo 'restore of popme-0.04/README failed'
shar_count="`wc -c < 'popme-0.04/README'`"
test 5441 -eq "$shar_count" ||
echo "popme-0.04/README: original size 5441, current size $shar_count"
fi
# ============= popme-0.04/THANKS ==============
if test -f 'popme-0.04/THANKS' && test X"$1" != X"-c"; then
echo 'x - skipping popme-0.04/THANKS (File already exists)'
else
echo 'x - extracting popme-0.04/THANKS (text)'
sed 's/^X//' << 'United Earthlings, Inc.' > 'popme-0.04/THANKS' &&
Popme THANKS file for version 0.04
X
Popme has originally been written by some else.
X
Some people further contributed to the program by reporting problems,
suggesting various improvements or submitting actual code. Here is a list of
these people. Help me keep it complete and exempt of errors.
X
Alan Cox <al...@LXORGUK.UKUU.ORG.UK>
Michael Somos <so...@grail.cba.csuohio.edu>
Robin A. Goodfellow <r...@earthling.net>
United Earthlings, Inc.
$shar_touch -am 1010102997 'popme-0.04/THANKS' &&
chmod 0644 'popme-0.04/THANKS' ||
echo 'restore of popme-0.04/THANKS failed'
shar_count="`wc -c < 'popme-0.04/THANKS'`"
test 416 -eq "$shar_count" ||
echo "popme-0.04/THANKS: original size 416, current size $shar_count"
fi
# ============= popme-0.04/getopt.c ==============
if test -f 'popme-0.04/getopt.c' && test X"$1" != X"-c"; then
echo 'x - skipping popme-0.04/getopt.c (File already exists)'
else
echo 'x - extracting popme-0.04/getopt.c (text)'
sed 's/^X//' << 'United Earthlings, Inc.' > 'popme-0.04/getopt.c' &&
/* Getopt for GNU.
X NOTE: getopt is now part of the C library, so if you don't know what
X "Keep this file name-space clean" means, talk to rol...@gnu.ai.mit.edu
X before changing it!
X
X Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
X
X This program is free software; you can redistribute it and/or modify it
X under the terms of the GNU General Public License as published by the
X Free Software Foundation; either version 2, or (at your option) any
X 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
X
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
X
/* AIX requires this to be the first thing in the file. */
#if __GNUC__ < 2
#define alloca __builtin_alloca
#else /* not __GNUC__ */
#if defined (HAVE_ALLOCA_H) || (defined(sparc) && (defined(sun) || (!defined(USG) && !defined(SVR4) && !defined(__svr4__))))
#include <alloca.h>
#else
#ifdef _AIX
#pragma alloca
#else
char *alloca ();
#endif
#endif /* alloca.h */
#endif /* not __GNUC__ */
X
#if !__STDC__ && !defined(const)
#define const
#endif
X
#include <stdio.h>
X
/* This needs to come after some library #include
X to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#undef alloca
/* Don't include stdlib.h for non-GNU C libraries because some of them
X contain conflicting prototypes for getopt. */
#include <stdlib.h>
#else /* Not GNU C library. */
#define __alloca alloca
#endif /* GNU C library. */
X
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
X long-named option. Because this is not POSIX.2 compliant, it is
X being phased out. */
/* #define GETOPT_COMPAT */
X
/* This version of `getopt' appears to the caller like standard Unix `getopt'
X but it behaves differently for the user, since it allows the user
X to intersperse the options with the other arguments.
X
X As `getopt' works, it permutes the elements of ARGV so that,
X when it is done, all the options precede everything else. Thus
X all application programs are extended to handle flexible argument order.
X
X Setting the environment variable POSIXLY_CORRECT disables permutation.
X Then the behavior is completely standard.
X
X GNU application programs can use a third alternative mode in which
X they can distinguish the relative order of options and other arguments. */
X
#include "getopt.h"
X
/* For communication from `getopt' to the caller.
X When `getopt' finds an option that takes an argument,
X the argument value is returned here.
X Also, when `ordering' is RETURN_IN_ORDER,
X each non-option ARGV-element is returned here. */
X
char *optarg = 0;
X
/* Index in ARGV of the next element to be scanned.
X This is used for communication to and from the caller
X and for communication between successive calls to `getopt'.
X
X On entry to `getopt', zero means this is the first call; initialize.
X
X When `getopt' returns EOF, this is the index of the first of the
X non-option elements that the caller should itself scan.
X
X Otherwise, `optind' communicates from one call to the next
X how much of ARGV has been scanned so far. */
X
int optind = 0;
X
/* The next char to be scanned in the option-element
X in which the last option character we returned was found.
X This allows us to pick up the scan where we left off.
X
X If this is zero, or a null string, it means resume the scan
X by advancing to the next ARGV-element. */
X
static char *nextchar;
X
/* Callers store zero here to inhibit the error message
X for unrecognized options. */
X
int opterr = 1;
X
/* Describe how to deal with options that follow non-option ARGV-elements.
X
X If the caller did not specify anything,
X the default is REQUIRE_ORDER if the environment variable
X POSIXLY_CORRECT is defined, PERMUTE otherwise.
X
X REQUIRE_ORDER means don't recognize them as options;
X stop option processing when the first non-option is seen.
X This is what Unix does.
X This mode of operation is selected by either setting the environment
X variable POSIXLY_CORRECT, or using `+' as the first character
X of the list of option characters.
X
X PERMUTE is the default. We permute the contents of ARGV as we scan,
X so that eventually all the non-options are at the end. This allows options
X to be given in any order, even with programs that were not written to
X expect this.
X
X RETURN_IN_ORDER is an option available to programs that were written
X to expect options and other ARGV-elements in any order and that care about
X the ordering of the two. We describe each non-option ARGV-element
X as if it were the argument of an option with character code 1.
X Using `-' as the first character of the list of option characters
X selects this mode of operation.
X
X The special argument `--' forces an end of option-scanning regardless
X of the value of `ordering'. In the case of RETURN_IN_ORDER, only
X `--' can cause `getopt' to return EOF with `optind' != ARGC. */
X
static enum
{
X REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} ordering;
X
#ifdef __GNU_LIBRARY__
/* We want to avoid inclusion of string.h with non-GNU libraries
X because there are many ways it can cause trouble.
X On some systems, it contains special magic macros that don't work
X in GCC. */
#include <string.h>
#define my_index strchr
#define my_bcopy(src, dst, n) memcpy ((dst), (src), (n))
#else
X
/* Avoid depending on library functions or files
X whose names are inconsistent. */
X
char *getenv ();
X
static char *
my_index (string, chr)
X char *string;
X int chr;
{
X while (*string)
X {
X if (*string == chr)
X return string;
X string++;
X }
X return 0;
}
X
static void
my_bcopy (from, to, size)
X char *from, *to;
X int size;
{
X int i;
X for (i = 0; i < size; i++)
X to[i] = from[i];
}
#endif /* GNU C library. */
X
/* Handle permutation of arguments. */
X
/* Describe the part of ARGV that contains non-options that have
X been skipped. `first_nonopt' is the index in ARGV of the first of them;
X `last_nonopt' is the index after the last of them. */
X
static int first_nonopt;
static int last_nonopt;
X
/* Exchange two adjacent subsequences of ARGV.
X One subsequence is elements [first_nonopt,last_nonopt)
X which contains all the non-options that have been skipped so far.
X The other is elements [last_nonopt,optind), which contains all
X the options processed since those non-options were skipped.
X
X `first_nonopt' and `last_nonopt' are relocated so that they describe
X the new indices of the non-options in ARGV after they are moved. */
X
static void
exchange (argv)
X char **argv;
{
X int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
X char **temp = (char **) __alloca (nonopts_size);
X
X /* Interchange the two blocks of data in ARGV. */
X
X my_bcopy ((char *) &argv[first_nonopt], (char *) temp, nonopts_size);
X my_bcopy ((char *) &argv[last_nonopt], (char *) &argv[first_nonopt],
X (optind - last_nonopt) * sizeof (char *));
X my_bcopy ((char *) temp,
X (char *) &argv[first_nonopt + optind - last_nonopt],
X nonopts_size);
X
X /* Update records for the slots the non-options now occupy. */
X
X first_nonopt += (optind - last_nonopt);
X last_nonopt = optind;
}
X
/* Scan elements of ARGV (whose length is ARGC) for option characters
X given in OPTSTRING.
X
X If an element of ARGV starts with '-', and is not exactly "-" or "--",
X then it is an option element. The characters of this element
X (aside from the initial '-') are option characters. If `getopt'
X is called repeatedly, it returns successively each of the option characters
X from each of the option elements.
X
X If `getopt' finds another option character, it returns that character,
X updating `optind' and `nextchar' so that the next call to `getopt' can
X resume the scan with the following option character or ARGV-element.
X
X If there are no more option characters, `getopt' returns `EOF'.
X Then `optind' is the index in ARGV of the first ARGV-element
X that is not an option. (The ARGV-elements have been permuted
X so that those that are not options now come last.)
X
X OPTSTRING is a string containing the legitimate option characters.
X If an option character is seen that is not listed in OPTSTRING,
X return '?' after printing an error message. If you set `opterr' to
X zero, the error message is suppressed but we still return '?'.
X
X If a char in OPTSTRING is followed by a colon, that means it wants an arg,
X so the following text in the same ARGV-element, or the text of the following
X ARGV-element, is returned in `optarg'. Two colons mean an option that
X wants an optional arg; if there is text in the current ARGV-element,
X it is returned in `optarg', otherwise `optarg' is set to zero.
X
X If OPTSTRING starts with `-' or `+', it requests different methods of
X handling the non-option ARGV-elements.
X See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
X
X Long-named options begin with `--' instead of `-'.
X Their names may be abbreviated as long as the abbreviation is unique
X or is an exact match for some defined option. If they have an
X argument, it follows the option name in the same ARGV-element, separated
X from the option name by a `=', or else the in next ARGV-element.
X When `getopt' finds a long-named option, it returns 0 if that option's
X `flag' field is nonzero, the value of the option's `val' field
X if the `flag' field is zero.
X
X The elements of ARGV aren't really const, because we permute them.
X But we pretend they're const in the prototype to be compatible
X with other systems.
X
X LONGOPTS is a vector of `struct option' terminated by an
X element containing a name which is zero.
X
X LONGIND returns the index in LONGOPT of the long-named option found.
X It is only valid when a long-named option has been found by the most
X recent call.
X
X If LONG_ONLY is nonzero, '-' as well as '--' can introduce
X long-named options. */
X
int
_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
X int argc;
X char *const *argv;
X const char *optstring;
X const struct option *longopts;
X int *longind;
X int long_only;
{
X int option_index;
X
X optarg = 0;
X
X /* Initialize the internal data when the first call is made.
X Start processing options with ARGV-element 1 (since ARGV-element 0
X is the program name); the sequence of previously skipped
X non-option ARGV-elements is empty. */
X
X if (optind == 0)
X {
X first_nonopt = last_nonopt = optind = 1;
X
X nextchar = NULL;
X
X /* Determine how to handle the ordering of options and nonoptions. */
X
X if (optstring[0] == '-')
X {
X ordering = RETURN_IN_ORDER;
X ++optstring;
X }
X else if (optstring[0] == '+')
X {
X ordering = REQUIRE_ORDER;
X ++optstring;
X }
X else if (getenv ("POSIXLY_CORRECT") != NULL)
X ordering = REQUIRE_ORDER;
X else
X ordering = PERMUTE;
X }
X
X if (nextchar == NULL || *nextchar == '\0')
X {
X if (ordering == PERMUTE)
X {
X /* If we have just processed some options following some non-options,
X exchange them so that the options come first. */
X
X if (first_nonopt != last_nonopt && last_nonopt != optind)
X exchange ((char **) argv);
X else if (last_nonopt != optind)
X first_nonopt = optind;
X
X /* Now skip any additional non-options
X and extend the range of non-options previously skipped. */
X
X while (optind < argc
X && (argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
X && (longopts == NULL
X || argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif /* GETOPT_COMPAT */
X )
X optind++;
X last_nonopt = optind;
X }
X
X /* Special ARGV-element `--' means premature end of options.
X Skip it like a null option,
X then exchange with previous non-options as if it were an option,
X then skip everything else like a non-option. */
X
X if (optind != argc && !strcmp (argv[optind], "--"))
X {
X optind++;
X
X if (first_nonopt != last_nonopt && last_nonopt != optind)
X exchange ((char **) argv);
X else if (first_nonopt == last_nonopt)
X first_nonopt = optind;
X last_nonopt = argc;
X
X optind = argc;
X }
X
X /* If we have done all the ARGV-elements, stop the scan
X and back over any non-options that we skipped and permuted. */
X
X if (optind == argc)
X {
X /* Set the next-arg-index to point at the non-options
X that we previously skipped, so the caller will digest them. */
X if (first_nonopt != last_nonopt)
X optind = first_nonopt;
X return EOF;
X }
X
X /* If we have come to a non-option and did not permute it,
X either stop the scan or describe it to the caller and pass it by. */
X
X if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
X && (longopts == NULL
X || argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif /* GETOPT_COMPAT */
X )
X {
X if (ordering == REQUIRE_ORDER)
X return EOF;
X optarg = argv[optind++];
X return 1;
X }
X
X /* We have found another option-ARGV-element.
X Start decoding its characters. */
X
X nextchar = (argv[optind] + 1
X + (longopts != NULL && argv[optind][1] == '-'));
X }
X
X if (longopts != NULL
X && ((argv[optind][0] == '-'
X && (argv[optind][1] == '-' || long_only))
#ifdef GETOPT_COMPAT
X || argv[optind][0] == '+'
#endif /* GETOPT_COMPAT */
X ))
X {
X const struct option *p;
X char *s = nextchar;
X int exact = 0;
X int ambig = 0;
X const struct option *pfound = NULL;
X int indfound = 0;
X
X while (*s && *s != '=')
X s++;
X
X /* Test all options for either exact match or abbreviated matches. */
X for (p = longopts, option_index = 0; p->name;
X p++, option_index++)
X if (!strncmp (p->name, nextchar, s - nextchar))
X {
X if (s - nextchar == strlen (p->name))
X {
X /* Exact match found. */
X pfound = p;
X indfound = option_index;
X exact = 1;
X break;
X }
X else if (pfound == NULL)
X {
X /* First nonexact match found. */
X pfound = p;
X indfound = option_index;
X }
X else
X /* Second nonexact match found. */
X ambig = 1;
X }
X
X if (ambig && !exact)
X {
X if (opterr)
X fprintf (stderr, "%s: option `%s' is ambiguous\n",
X argv[0], argv[optind]);
X nextchar += strlen (nextchar);
X optind++;
X return '?';
X }
X
X if (pfound != NULL)
X {
X option_index = indfound;
X optind++;
X if (*s)
X {
X /* Don't test has_arg with >, because some C compilers don't
X allow it to be used on enums. */
X if (pfound->has_arg)
X optarg = s + 1;
X else
X {
X if (opterr)
X {
X if (argv[optind - 1][1] == '-')
X /* --option */
X fprintf (stderr,
X "%s: option `--%s' doesn't allow an argument\n",
X argv[0], pfound->name);
X else
X /* +option or -option */
X fprintf (stderr,
X "%s: option `%c%s' doesn't allow an argument\n",
X argv[0], argv[optind - 1][0], pfound->name);
X }
X nextchar += strlen (nextchar);
X return '?';
X }
X }
X else if (pfound->has_arg == 1)
X {
X if (optind < argc)
X optarg = argv[optind++];
X else
X {
X if (opterr)
X fprintf (stderr, "%s: option `%s' requires an argument\n",
X argv[0], argv[optind - 1]);
X nextchar += strlen (nextchar);
X return '?';
X }
X }
X nextchar += strlen (nextchar);
X if (longind != NULL)
X *longind = option_index;
X if (pfound->flag)
X {
X *(pfound->flag) = pfound->val;
X return 0;
X }
X return pfound->val;
X }
X /* Can't find it as a long option. If this is not getopt_long_only,
X or the option starts with '--' or is not a valid short
X option, then it's an error.
X Otherwise interpret it as a short option. */
X if (!long_only || argv[optind][1] == '-'
#ifdef GETOPT_COMPAT
X || argv[optind][0] == '+'
#endif /* GETOPT_COMPAT */
X || my_index (optstring, *nextchar) == NULL)
X {
X if (opterr)
X {
X if (argv[optind][1] == '-')
X /* --option */
X fprintf (stderr, "%s: unrecognized option `--%s'\n",
X argv[0], nextchar);
X else
X /* +option or -option */
X fprintf (stderr, "%s: unrecognized option `%c%s'\n",
X argv[0], argv[optind][0], nextchar);
X }
X nextchar = (char *) "";
X optind++;
X return '?';
X }
X }
X
X /* Look at and handle the next option-character. */
X
X {
X char c = *nextchar++;
X char *temp = my_index (optstring, c);
X
X /* Increment `optind' when we start to process its last character. */
X if (*nextchar == '\0')
X ++optind;
X
X if (temp == NULL || c == ':')
X {
X if (opterr)
X {
X if (c < 040 || c >= 0177)
X fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
X argv[0], c);
X else
X fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
X }
X return '?';
X }
X if (temp[1] == ':')
X {
X if (temp[2] == ':')
X {
X /* This is an option that accepts an argument optionally. */
X if (*nextchar != '\0')
X {
X optarg = nextchar;
X optind++;
X }
X else
X optarg = 0;
X nextchar = NULL;
X }
X else
X {
X /* This is an option that requires an argument. */
X if (*nextchar != '\0')
X {
X optarg = nextchar;
X /* If we end this ARGV-element by taking the rest as an arg,
X we must advance to the next element now. */
X optind++;
X }
X else if (optind == argc)
X {
X if (opterr)
X fprintf (stderr, "%s: option `-%c' requires an argument\n",
X argv[0], c);
X c = '?';
X }
X else
X /* We already incremented `optind' once;
X increment it again when taking next ARGV-elt as argument. */
X optarg = argv[optind++];
X nextchar = NULL;
X }
X }
X return c;
X }
}
X
int
getopt (argc, argv, optstring)
X int argc;
X char *const *argv;
X const char *optstring;
{
X return _getopt_internal (argc, argv, optstring,
X (const struct option *) 0,
X (int *) 0,
X 0);
}
X
#ifdef TEST
X
/* Compile with -DTEST to make an executable for use in testing
X the above definition of `getopt'. */
X
int
main (argc, argv)
X int argc;
X char **argv;
{
X int c;
X int digit_optind = 0;
X
X while (1)
X {
X int this_option_optind = optind ? optind : 1;
X
X c = getopt (argc, argv, "abc:d:0123456789");
X if (c == EOF)
X break;
X
X switch (c)
X {
X case '0':
X case '1':
X case '2':
X case '3':
X case '4':
X case '5':
X case '6':
X case '7':
X case '8':
X case '9':
X if (digit_optind != 0 && digit_optind != this_option_optind)
X printf ("digits occur in two different argv-elements.\n");
X digit_optind = this_option_optind;
X printf ("option %c\n", c);
X break;
X
X case 'a':
X printf ("option a\n");
X break;
X
X case 'b':
X printf ("option b\n");
X break;
X
X case 'c':
X printf ("option c with value `%s'\n", optarg);
X break;
X
X case '?':
X break;
X
X default:
X printf ("?? getopt returned character code 0%o ??\n", c);
X }
X }
X
X if (optind < argc)
X {
X printf ("non-option ARGV-elements: ");
X while (optind < argc)
X printf ("%s ", argv[optind++]);
X printf ("\n");
X }
X
X exit (0);
}
X
#endif /* TEST */
United Earthlings, Inc.
$shar_touch -am 1010102297 'popme-0.04/getopt.c' &&
chmod 0644 'popme-0.04/getopt.c' ||
echo 'restore of popme-0.04/getopt.c failed'
shar_count="`wc -c < 'popme-0.04/getopt.c'`"
test 19370 -eq "$shar_count" ||
echo "popme-0.04/getopt.c: original size 19370, current size $shar_count"
fi
: || echo 'restore of popme-0.04/getopt1.c failed'
echo 'End of part 1, continue with part 2'
exit 0
--
Choose life, -rag

Robin A. Goodfellow
Philosopher, Thinker, Hacker. "The structure is that there
United Earthlings, Inc. is no structure at all."
r...@earthling.net --Andrew S. Tanenbaum

Reply all
Reply to author
Forward
0 new messages