]> git.deb.at Git - pkg/abook.git/commitdiff
Imported Upstream version 0.4.16 upstream/0.4.16
authorGerfried Fuchs <rhonda@debian.org>
Thu, 22 Mar 2012 16:28:50 +0000 (17:28 +0100)
committerGerfried Fuchs <rhonda@debian.org>
Thu, 22 Mar 2012 16:28:50 +0000 (17:28 +0100)
67 files changed:
ANNOUNCE [new file with mode: 0644]
AUTHORS [new file with mode: 0644]
BUGS [new file with mode: 0644]
COPYING [new file with mode: 0644]
ChangeLog [new file with mode: 0644]
FAQ [new file with mode: 0644]
INSTALL [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
Makefile.in [new file with mode: 0644]
NEWS [new file with mode: 0644]
README [new file with mode: 0644]
THANKS [new file with mode: 0644]
TODO [new file with mode: 0644]
abook.1 [new file with mode: 0644]
abook.c [new file with mode: 0644]
abook.h [new file with mode: 0644]
abook_curses.h [new file with mode: 0644]
abookrc.5 [new file with mode: 0644]
acconfig.h [new file with mode: 0644]
acinclude.m4 [new file with mode: 0644]
aclocal.m4 [new file with mode: 0644]
conff.c [new file with mode: 0644]
conff.h [new file with mode: 0644]
config.guess [new file with mode: 0644]
config.h.in [new file with mode: 0644]
config.sub [new file with mode: 0644]
configure [new file with mode: 0755]
configure.in [new file with mode: 0644]
contrib/abook+vim/README [new file with mode: 0644]
contrib/abook+vim/mail.vim [new file with mode: 0644]
contrib/epm/README [new file with mode: 0644]
contrib/epm/abook.list.in [new file with mode: 0644]
contrib/epm/configure.in [new file with mode: 0644]
contrib/epm/configure.in.patch [new file with mode: 0644]
contrib/mail2abook.py [new file with mode: 0755]
contrib/vcard2abook.pl [new file with mode: 0755]
contrib/whitelist/README [new file with mode: 0644]
contrib/whitelist/abook2whitelist.sh [new file with mode: 0755]
contrib/whitelist/mutt.whitelist [new file with mode: 0644]
contrib/whitelist/patch.orig.obsolete [new file with mode: 0644]
contrib/whitelist/whitelist.rc [new file with mode: 0755]
database.c [new file with mode: 0644]
database.h [new file with mode: 0644]
edit.c [new file with mode: 0644]
edit.h [new file with mode: 0644]
estr.c [new file with mode: 0644]
estr.h [new file with mode: 0644]
filter.c [new file with mode: 0644]
filter.h [new file with mode: 0644]
getname.c [new file with mode: 0644]
getname.h [new file with mode: 0644]
help.h [new file with mode: 0644]
install-sh [new file with mode: 0755]
ldif.c [new file with mode: 0644]
ldif.h [new file with mode: 0644]
list.c [new file with mode: 0644]
list.h [new file with mode: 0644]
misc.c [new file with mode: 0644]
misc.h [new file with mode: 0644]
missing [new file with mode: 0755]
mkinstalldirs [new file with mode: 0755]
options.c [new file with mode: 0644]
options.h [new file with mode: 0644]
sample.abookrc [new file with mode: 0644]
stamp-h.in [new file with mode: 0644]
ui.c [new file with mode: 0644]
ui.h [new file with mode: 0644]

diff --git a/ANNOUNCE b/ANNOUNCE
new file mode 100644 (file)
index 0000000..2542b27
--- /dev/null
+++ b/ANNOUNCE
@@ -0,0 +1,7 @@
+abook v 0.4
+
+Abook is small and powerful addressbook program designed to use with mutt mail
+client. Abook runs on Linux / FreeBSD and probably with small changes on other
+unices. Ncurses library is required to compile abook.
+
+Abook is available at http://abook.sourceforge.net/
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..2d83e7e
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,21 @@
+abook AUTHORS
+-------------
+
+Jaakko Heinonen                <jheinonen@users.sourceforge.net>
+
+Alan Ford              <alan@whirlnet.co.uk>
+ - Debian package
+ - manual pages
+ - GnomeCard, csv, text, elm export filters
+ - etc.
+
+Josua Groeger          <fractalus@gmx.net>
+ - spruce export filter
+ - text export filter update
+
+Matt Kraai             <kraai@alumni.carnegiemellon.edu>
+ - patches
+
+Koenraad Heijlen       <vipie@ulyssis.org>
+ - csv import filter
+ - fixes
diff --git a/BUGS b/BUGS
new file mode 100644 (file)
index 0000000..c877bf4
--- /dev/null
+++ b/BUGS
@@ -0,0 +1,9 @@
+known bugs in abook
+
+* in X terminals keyboard may not behave as expected - this is probably
+  a ncurses problem
+* incompatible with some terminals
+* --datafile option is a bit broken
+
+* mutt / elm / pine export filters allow to create a file with duplicate
+  aliases
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..eeb586b
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+                   GNU GENERAL PUBLIC LICENSE
+                      Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+\f
+                   GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+\f
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+\f
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+\f
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                           NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                    END OF TERMS AND CONDITIONS
+\f
+           How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) 19yy  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) 19yy name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..d08feb5
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,196 @@
+0.4.16
+ - use strcoll instead of strcmp for sorting entries
+ - html filter fix
+ - many bugfixes
+
+0.4.15
+ - new options --add-email and --add-email-quiet
+ - proper mutt alias import filter
+ - editor update
+ - don't handle extra_column and extra_alternative as numbers in abookrc
+ - added second address field
+ - mail.vim update in contrib directory
+
+0.4.14
+ - added csv import filter
+ - csv export filter fix
+ - minor html filter update
+ - fixed a minor memory leak in pine import filter
+ - filter cleanups
+ - fixes
+ - "quit and print selected item(s) to stderr" command (Brian Medley)
+ - contrib update
+
+0.4.13
+ - major code reorganization (phase 1)
+ - fixed help viewer functions
+ - ability to disable use of non-ascii characters (configuration option)
+ - changed SIGINT behaviour
+ - html export filter creates now valid html documents
+ - ability to print/export only selected items
+ - new editor commands
+ - text filter update
+ - query/find code cleanup
+ - fixed snprintf related bugs
+ - minor bugfixes
+
+0.4.12
+ - added man page for abookrc (Alan Ford)
+ - notes are returned as optional data in mutt queries
+ - created a workaround for a mutt query bug
+ - new "extra_alternative" config option (Alan)
+ - added undo feature to editor
+ - FAQ
+ - macro updates
+ - fixed the cancel key behavior in editor
+
+0.4.11
+ - new configuration file format
+ - new sorting routines
+ - minor mutt query patch (Matt)
+ - html filter update
+ - added mail2abook.py script to improve the mutt integration
+ - memory allocation changes
+ - contrib update
+
+0.4.10
+ - mutt alias import filter
+ - --datafile option should work better now
+ - merged HPUX patch (submitted by Matt Kraai)
+ - added field for nickname/alias
+ - bugfixes
+
+0.4.9
+ - increased the maximum length of an e-mail address
+ - added Spruce and ldif export filters
+ - text filter update
+ - added support for systemwide configuration file (/etc/abook.conf)
+ - list.c cleanup
+ - minor fixes
+
+0.4.8
+ - new enter_string function (scrollable input)
+ - fileselector
+ - new fields for phone numbers
+ - extra field support
+ - added open database command and --datafile option
+
+0.4.7
+ - fixed terminal resizing bug
+ - new man page
+ - fixed "roll emails" bug
+ - merged Alan's urlview patch
+ - fixed some compile warnings on some systems
+
+0.4.6
+ - new proper ldif import filter
+ - printing
+ - GnomeCard export filter
+ - improved ui
+ - csv export filter
+ - elm alias export filter
+ - plain text export filter
+ - improved import / export system
+ - a man page (contributed by Alan Ford)
+ - some fixes
+
+0.4.5
+ - new command line option --convert to make format conversions
+ - new common functions for filters
+ - mutt alias export filter
+ - minor filter updates
+ - fixed a compile problem in list.c 
+
+0.4.4
+ - fixed a serious segfault bug in editor
+ - conff.c update
+
+0.4.3
+ - improved "send mail with mutt" command
+ - optimized screen refreshing
+ - abook handles now SIGINT, SIGKILL, SIGTERM signals
+
+0.4.2
+ - new editor
+ - added fields for address (address, city, state, zip, country)
+ - terminal resizing is now handled by abook
+ - improved scrolling
+ - bugfixes 
+ - dropped support for abook 0.1 / 0.2 file format
+
+0.4.1
+ - fixed a redraw bug in editor which occurred only with old ncurses library
+ - minor updates 
+
+0.4.0
+ - PINE addressbook import and export filters added
+ - new faster load and save functions
+ - changed memory allocation method
+ - better configuration system - options.c rewritten
+ - new version of conff.c
+ - find segfault bug fixed
+ - fixed overwriting policy
+
+0.3.1
+ - fixed a bug which caused list to disappear sometimes after removing items
+ - minor changes in datafile loader
+ - abook.gz import filter is now disabled as default
+
+0.3.0
+ - new portable file format
+ - import filter for old data format
+ - now compiles on FreeBSD
+ - new "send mail with mutt" command
+ - multiple e-mail address support
+ - html export filter
+ - improved cursor behavior
+ - fixed misc.c
+ - new configuration system ( ~/.abook.conf )
+ - improved memory allocation functions
+ - added invert selection command 
+ - minor filter updates
+
+0.2.4
+ - minor memory freeing fix 
+
+0.2.3
+ - major memory allocation bugfix
+
+0.2.2
+ - bugfixes
+
+0.2.1
+ - abook finaly uses automake/autoconf setup
+ - documentation updated
+ - minor changes 
+
+0.2.0
+ - multiple selection
+ - added find function
+ - ldif import filter update (still some bugs?)
+ - added check for terminal size
+ - removed obsolete rcfile code
+ - some changes in list.c
+ - new file: help.h
+ - Makefiles modified
+ - complete rewrote of misc.c
+ - fixed a bug in mutt query
+ - changed first_item to first_list_item and LAST_ITEM to LAST_LIST_ITEM
+ - lots of minor improvements
+ - documentation updated (it's still very bad)
+
+0.1.0
+ - removed dummy defaultrc.h file
+ - README and COPYING
+ - minor ldif import filter update
+ - minor changes and fixes
+
+0.1.0-pre-release 2
+ - locale support
+ - mutt query now ignores case
+ - rcfile support is compiled only if -DEXPERIMENTAL option is selected (see
+   Makefile) because the rcfile support is very poor and should
+   be rewritten for 0.2 or something
+ - new file: defaultrc.h
+
+0.1.0-pre-release 1
diff --git a/FAQ b/FAQ
new file mode 100644 (file)
index 0000000..e96731a
--- /dev/null
+++ b/FAQ
@@ -0,0 +1,35 @@
+abook FAQ
+~~~~~~~~~
+
+Q: How to query all addresses when I press 'Q' in mutt?
+
+A: Type "all" to the prompt.
+
+
+Q: Can I mark multiple addresses in mutt after a query?
+
+A: You can tag addresses with 't'. When ready, type ";m" (press first ';'
+   and then 'm') and all tagged addresses will appear to your "To:"
+   line.
+
+
+Q: How to insert an address (or many) with abook when I'm forwarding
+   a message in mutt? ("To:" and "Cc:" prompts)
+
+A: When "To:" or "Cc:" prompt appears press ^t for query. (After query
+   you can tag multiple addresses with 't')
+
+
+Q: Can I add addresses to the abook addressbook from mutt?
+
+A: Yes, it is possible starting from abook 0.4.15. See --add-email
+   command line option and README.
+
+
+Q: Does abook support palm addressbooks?
+
+A: No, but there are utilities to convert palm addressbooks to ldif
+   files. Abook can import ldif files.
+
+
+last update: $Date: 2001/10/17 16:31:04 $
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..b42a17a
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,182 @@
+Basic Installation
+==================
+
+   These are generic installation instructions.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, a file
+`config.cache' that saves the results of its tests to speed up
+reconfiguring, and a file `config.log' containing compiler output
+(useful mainly for debugging `configure').
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If at some point `config.cache'
+contains results you don't want to keep, you may remove or edit it.
+
+   The file `configure.in' is used to create `configure' by a program
+called `autoconf'.  You only need `configure.in' if you want to change
+it or regenerate `configure' using a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.  If you're
+     using `csh' on an old version of System V, you might need to type
+     `sh ./configure' instead to prevent `csh' from trying to execute
+     `configure' itself.
+
+     Running `configure' takes awhile.  While running, it prints some
+     messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+Compilers and Options
+=====================
+
+   Some systems require unusual options for compilation or linking that
+the `configure' script does not know about.  You can give `configure'
+initial values for variables by setting them in the environment.  Using
+a Bourne-compatible shell, you can do that on the command line like
+this:
+     CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
+
+Or on systems that have the `env' program, you can do it like this:
+     env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
+
+Compiling For Multiple Architectures
+====================================
+
+   You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   If you have to use a `make' that does not supports the `VPATH'
+variable, you have to compile the package for one architecture at a time
+in the source code directory.  After you have installed the package for
+one architecture, use `make distclean' before reconfiguring for another
+architecture.
+
+Installation Names
+==================
+
+   By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc.  You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PATH'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+   Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+   There may be some features `configure' can not figure out
+automatically, but needs to determine by the type of host the package
+will run on.  Usually `configure' can figure that out, but if it prints
+a message saying it can not guess the host type, give it the
+`--host=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name with three fields:
+     CPU-COMPANY-SYSTEM
+
+See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the host type.
+
+   If you are building compiler tools for cross-compiling, you can also
+use the `--target=TYPE' option to select the type of system they will
+produce code for and the `--build=TYPE' option to select the type of
+system on which you are compiling the package.
+
+Sharing Defaults
+================
+
+   If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Operation Controls
+==================
+
+   `configure' recognizes the following options to control how it
+operates.
+
+`--cache-file=FILE'
+     Use and save the results of the tests in FILE instead of
+     `./config.cache'.  Set FILE to `/dev/null' to disable caching, for
+     debugging `configure'.
+
+`--help'
+     Print a summary of the options to `configure', and exit.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`--version'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`configure' also accepts some other, not widely useful, options.
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..a376bf3
--- /dev/null
@@ -0,0 +1,18 @@
+
+bin_PROGRAMS = abook
+
+abook_SOURCES = abook.c database.c filter.c list.c misc.c conff.c \
+               options.c edit.c ldif.c estr.c ui.c getname.c \
+               abook.h database.h filter.h list.h misc.h help.h conff.h \
+               options.h edit.h ldif.h estr.h abook_curses.h ui.h getname.h
+
+EXTRA_DIST = ANNOUNCE BUGS FAQ abook.1 abookrc.5 sample.abookrc
+
+install-data-local:
+       $(mkinstalldirs) $(DESTDIR)$(mandir)/man1 $(DESTDIR)$(mandir)/man5
+       $(INSTALL_DATA) $(srcdir)/abook.1 $(DESTDIR)$(mandir)/man1/
+       $(INSTALL_DATA) $(srcdir)/abookrc.5 $(DESTDIR)$(mandir)/man5/
+
+uninstall-local:
+       -rm -f $(DESTDIR)$(mandir)/man1/abook.1
+       -rm -f $(DESTDIR)$(mandir)/man5/abookrc.5
diff --git a/Makefile.in b/Makefile.in
new file mode 100644 (file)
index 0000000..9f408e7
--- /dev/null
@@ -0,0 +1,391 @@
+# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
+
+# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+
+DESTDIR =
+
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+
+top_builddir = .
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+transform = @program_transform_name@
+
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+host_alias = @host_alias@
+host_triplet = @host@
+CC = @CC@
+CPP = @CPP@
+MAKEINFO = @MAKEINFO@
+PACKAGE = @PACKAGE@
+U = @U@
+VERSION = @VERSION@
+
+bin_PROGRAMS = abook
+
+abook_SOURCES = abook.c database.c filter.c list.c misc.c conff.c \
+               options.c edit.c ldif.c estr.c ui.c getname.c \
+               abook.h database.h filter.h list.h misc.h help.h conff.h \
+               options.h edit.h ldif.h estr.h abook_curses.h ui.h getname.h
+
+
+EXTRA_DIST = ANNOUNCE BUGS FAQ abook.1 abookrc.5 sample.abookrc
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = config.h
+CONFIG_CLEAN_FILES = 
+PROGRAMS =  $(bin_PROGRAMS)
+
+
+DEFS = @DEFS@ -I. -I$(srcdir) -I.
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+abook_OBJECTS =  abook.o database.o filter.o list.o misc.o conff.o \
+options.o edit.o ldif.o estr.o ui.o getname.o
+abook_LDADD = $(LDADD)
+abook_DEPENDENCIES = 
+abook_LDFLAGS = 
+CFLAGS = @CFLAGS@
+COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
+DIST_COMMON =  README ./stamp-h.in AUTHORS COPYING ChangeLog INSTALL \
+Makefile.am Makefile.in NEWS THANKS TODO acconfig.h acinclude.m4 \
+aclocal.m4 config.guess config.h.in config.sub configure configure.in \
+install-sh missing mkinstalldirs
+
+
+DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
+
+TAR = gtar
+GZIP_ENV = --best
+SOURCES = $(abook_SOURCES)
+OBJECTS = $(abook_OBJECTS)
+
+all: all-redirect
+.SUFFIXES:
+.SUFFIXES: .S .c .o .s
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
+       cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps Makefile
+
+Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
+       cd $(top_builddir) \
+         && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+$(ACLOCAL_M4):  configure.in  acinclude.m4
+       cd $(srcdir) && $(ACLOCAL)
+
+config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+       $(SHELL) ./config.status --recheck
+$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
+       cd $(srcdir) && $(AUTOCONF)
+
+config.h: stamp-h
+       @if test ! -f $@; then \
+               rm -f stamp-h; \
+               $(MAKE) stamp-h; \
+       else :; fi
+stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status
+       cd $(top_builddir) \
+         && CONFIG_FILES= CONFIG_HEADERS=config.h \
+            $(SHELL) ./config.status
+       @echo timestamp > stamp-h 2> /dev/null
+$(srcdir)/config.h.in: $(srcdir)/stamp-h.in
+       @if test ! -f $@; then \
+               rm -f $(srcdir)/stamp-h.in; \
+               $(MAKE) $(srcdir)/stamp-h.in; \
+       else :; fi
+$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h
+       cd $(top_srcdir) && $(AUTOHEADER)
+       @echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null
+
+mostlyclean-hdr:
+
+clean-hdr:
+
+distclean-hdr:
+       -rm -f config.h
+
+maintainer-clean-hdr:
+
+mostlyclean-binPROGRAMS:
+
+clean-binPROGRAMS:
+       -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+
+distclean-binPROGRAMS:
+
+maintainer-clean-binPROGRAMS:
+
+install-binPROGRAMS: $(bin_PROGRAMS)
+       @$(NORMAL_INSTALL)
+       $(mkinstalldirs) $(DESTDIR)$(bindir)
+       @list='$(bin_PROGRAMS)'; for p in $$list; do \
+         if test -f $$p; then \
+           echo "  $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
+            $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
+         else :; fi; \
+       done
+
+uninstall-binPROGRAMS:
+       @$(NORMAL_UNINSTALL)
+       list='$(bin_PROGRAMS)'; for p in $$list; do \
+         rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
+       done
+
+.c.o:
+       $(COMPILE) -c $<
+
+.s.o:
+       $(COMPILE) -c $<
+
+.S.o:
+       $(COMPILE) -c $<
+
+mostlyclean-compile:
+       -rm -f *.o core *.core
+
+clean-compile:
+
+distclean-compile:
+       -rm -f *.tab.c
+
+maintainer-clean-compile:
+
+abook: $(abook_OBJECTS) $(abook_DEPENDENCIES)
+       @rm -f abook
+       $(LINK) $(abook_LDFLAGS) $(abook_OBJECTS) $(abook_LDADD) $(LIBS)
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP)
+       list='$(SOURCES) $(HEADERS)'; \
+       unique=`for i in $$list; do echo $$i; done | \
+         awk '    { files[$$0] = 1; } \
+              END { for (i in files) print i; }'`; \
+       here=`pwd` && cd $(srcdir) \
+         && mkid -f$$here/ID $$unique $(LISP)
+
+TAGS:  $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP)
+       tags=; \
+       here=`pwd`; \
+       list='$(SOURCES) $(HEADERS)'; \
+       unique=`for i in $$list; do echo $$i; done | \
+         awk '    { files[$$0] = 1; } \
+              END { for (i in files) print i; }'`; \
+       test -z "$(ETAGS_ARGS)config.h.in$$unique$(LISP)$$tags" \
+         || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags config.h.in $$unique $(LISP) -o $$here/TAGS)
+
+mostlyclean-tags:
+
+clean-tags:
+
+distclean-tags:
+       -rm -f TAGS ID
+
+maintainer-clean-tags:
+
+distdir = $(PACKAGE)-$(VERSION)
+top_distdir = $(distdir)
+
+# This target untars the dist file and tries a VPATH configuration.  Then
+# it guarantees that the distribution is self-contained by making another
+# tarfile.
+distcheck: dist
+       -rm -rf $(distdir)
+       GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz
+       mkdir $(distdir)/=build
+       mkdir $(distdir)/=inst
+       dc_install_base=`cd $(distdir)/=inst && pwd`; \
+       cd $(distdir)/=build \
+         && ../configure --srcdir=.. --prefix=$$dc_install_base \
+         && $(MAKE) $(AM_MAKEFLAGS) \
+         && $(MAKE) $(AM_MAKEFLAGS) dvi \
+         && $(MAKE) $(AM_MAKEFLAGS) check \
+         && $(MAKE) $(AM_MAKEFLAGS) install \
+         && $(MAKE) $(AM_MAKEFLAGS) installcheck \
+         && $(MAKE) $(AM_MAKEFLAGS) dist
+       -rm -rf $(distdir)
+       @banner="$(distdir).tar.gz is ready for distribution"; \
+       dashes=`echo "$$banner" | sed s/./=/g`; \
+       echo "$$dashes"; \
+       echo "$$banner"; \
+       echo "$$dashes"
+dist: distdir
+       -chmod -R a+r $(distdir)
+       GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
+       -rm -rf $(distdir)
+dist-all: distdir
+       -chmod -R a+r $(distdir)
+       GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
+       -rm -rf $(distdir)
+distdir: $(DISTFILES)
+       -rm -rf $(distdir)
+       mkdir $(distdir)
+       -chmod 777 $(distdir)
+       @for file in $(DISTFILES); do \
+         d=$(srcdir); \
+         if test -d $$d/$$file; then \
+           cp -pr $$d/$$file $(distdir)/$$file; \
+         else \
+           test -f $(distdir)/$$file \
+           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+           || cp -p $$d/$$file $(distdir)/$$file || :; \
+         fi; \
+       done
+abook.o: abook.c config.h abook.h ui.h abook_curses.h options.h conff.h \
+       database.h list.h filter.h edit.h misc.h getname.h
+conff.o: conff.c misc.h config.h conff.h
+database.o: database.c abook.h database.h list.h ui.h abook_curses.h \
+       config.h options.h conff.h misc.h filter.h edit.h
+edit.o: edit.c abook_curses.h config.h ui.h options.h conff.h abook.h \
+       database.h list.h edit.h misc.h
+estr.o: estr.c abook_curses.h config.h options.h conff.h estr.h abook.h \
+       misc.h
+filter.o: filter.c abook_curses.h config.h filter.h database.h abook.h \
+       edit.h list.h ui.h options.h conff.h misc.h ldif.h getname.h
+getname.o: getname.c getname.h
+ldif.o: ldif.c ldif.h
+list.o: list.c abook.h ui.h abook_curses.h config.h options.h conff.h \
+       database.h edit.h list.h misc.h
+misc.o: misc.c config.h misc.h abook.h
+options.o: options.c abook_curses.h config.h abook.h options.h conff.h
+ui.o: ui.c abook.h ui.h abook_curses.h config.h options.h conff.h edit.h \
+       database.h list.h misc.h filter.h estr.h help.h
+
+info-am:
+info: info-am
+dvi-am:
+dvi: dvi-am
+check-am: all-am
+check: check-am
+installcheck-am:
+installcheck: installcheck-am
+all-recursive-am: config.h
+       $(MAKE) $(AM_MAKEFLAGS) all-recursive
+
+install-exec-am: install-binPROGRAMS
+install-exec: install-exec-am
+
+install-data-am: install-data-local
+install-data: install-data-am
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+install: install-am
+uninstall-am: uninstall-binPROGRAMS uninstall-local
+uninstall: uninstall-am
+all-am: Makefile $(PROGRAMS) config.h
+all-redirect: all-am
+install-strip:
+       $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
+installdirs:
+       $(mkinstalldirs)  $(DESTDIR)$(bindir)
+
+
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+       -rm -f Makefile $(CONFIG_CLEAN_FILES)
+       -rm -f config.cache config.log stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+mostlyclean-am:  mostlyclean-hdr mostlyclean-binPROGRAMS \
+               mostlyclean-compile mostlyclean-tags \
+               mostlyclean-generic
+
+mostlyclean: mostlyclean-am
+
+clean-am:  clean-hdr clean-binPROGRAMS clean-compile clean-tags \
+               clean-generic mostlyclean-am
+
+clean: clean-am
+
+distclean-am:  distclean-hdr distclean-binPROGRAMS distclean-compile \
+               distclean-tags distclean-generic clean-am
+
+distclean: distclean-am
+       -rm -f config.status
+
+maintainer-clean-am:  maintainer-clean-hdr maintainer-clean-binPROGRAMS \
+               maintainer-clean-compile maintainer-clean-tags \
+               maintainer-clean-generic distclean-am
+       @echo "This command is intended for maintainers to use;"
+       @echo "it deletes files that may require special tools to rebuild."
+
+maintainer-clean: maintainer-clean-am
+       -rm -f config.status
+
+.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \
+mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \
+maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \
+mostlyclean-compile distclean-compile clean-compile \
+maintainer-clean-compile tags mostlyclean-tags distclean-tags \
+clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \
+check-am installcheck-am installcheck all-recursive-am install-exec-am \
+install-exec install-data-local install-data-am install-data install-am \
+install uninstall-local uninstall-am uninstall all-redirect all-am all \
+installdirs mostlyclean-generic distclean-generic clean-generic \
+maintainer-clean-generic clean mostlyclean distclean maintainer-clean
+
+
+install-data-local:
+       $(mkinstalldirs) $(DESTDIR)$(mandir)/man1 $(DESTDIR)$(mandir)/man5
+       $(INSTALL_DATA) $(srcdir)/abook.1 $(DESTDIR)$(mandir)/man1/
+       $(INSTALL_DATA) $(srcdir)/abookrc.5 $(DESTDIR)$(mandir)/man5/
+
+uninstall-local:
+       -rm -f $(DESTDIR)$(mandir)/man1/abook.1
+       -rm -f $(DESTDIR)$(mandir)/man5/abookrc.5
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
+++ b/NEWS
@@ -0,0 +1 @@
+
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..b94900c
--- /dev/null
+++ b/README
@@ -0,0 +1,68 @@
+
+ ABOOK by JH <jheinonen@users.sourceforge.net>
+ -----
+
+Abook is an addressbook program with mutt mail client support.
+
+COMPILATION
+
+To compile abook you must have ncurses developement libraries installed.
+Starting from version 0.4.10 abook is know to compile with the native curses
+library of SUN Solaris and OpenBSD.
+
+If you compile with --enable-debug flag you should run abook like this:
+abook 2> debug or abook 2> /dev/null. Abook has been compiled and tested
+successfully on following platforms: (NOTE: All versions of abook haven't
+been tested on all platforms.)
+
+Linux (Debian GNU/Linux 2.1/2.2, RedHat 6.x)
+Solaris 2.4
+Solaris 2.5
+Solaris 2.6
+FreeBSD 3.3 (newer versions should be OK)
+OpenBSD
+NetBSD (reportedly requires ncurses to work properly)
+AIX 3.2.5
+HPUX
+Irix 6.5
+DEC alpha ?
+GNU/Hurd
+
+INSTALLATION
+
+See INSTALL for detailed instructions.
+
+If you want to use abook with mutt you should add following lines to your
+~/.muttrc or to the systemwide /etc/Muttrc file.
+
+set query_command="abook --mutt-query '%s'"
+macro pager A |'abook --add-email'\n
+
+After this you can make queries from mutt using the query command ('Q')
+and add sender e-mail addresses to the addressbook from pager using 'A'
+command. (Of course you can choose another keybinding if you like.)
+
+NOTES
+
+If your language specific characters don't work correctly make sure
+that your locale configuration has been done properly. (On Linux you
+must set at least LC_CTYPE environment variable)
+
+If you want to import a ldif file generated by abook in Netscape you
+must use the extension ``.4ld''.
+
+OBTAINING ABOOK
+
+Get the latest version from http://abook.sourceforge.net/
+
+LICENSE
+
+All files in this distribution are released under GNU GENERAL PUBLIC LICENSE.
+See COPYING for details.
+
+CONTACT AUTHOR
+
+Send bugreports, fixes, wishes etc. to Jaakko Heinonen
+<jheinonen@users.sourceforge.net> or preferably use the mailing list. (See
+http://abook.sourceforge.net/ for details)
+
diff --git a/THANKS b/THANKS
new file mode 100644 (file)
index 0000000..1ecc899
--- /dev/null
+++ b/THANKS
@@ -0,0 +1,15 @@
+abook THANKS
+------------
+
+Michael Wiedmann       <mw@miwie.in-berlin.de>
+Brian Salter-Duke      <b_duke@lacebark.ntu.edu.au>
+An Thi-Nguyen Le       <anle@ews.uiuc.edu>
+Reinhard J Sammer      <reinhard@sammer.net>
+Matt Anderson          <anderm3@cs.rpi.edu>
+R. Shohn Trojacek      <snazzle@galvani.tamu.edu>
+?                      <antirez@invece.org>
+Shao Zhang             <shao@cia.com.au>
+Gustavo Niemeyer       <gustavo@niemeyer.net>
+Brian Medley           <brian.medley@verizon.net>
+
+See also AUTHORS
diff --git a/TODO b/TODO
new file mode 100644 (file)
index 0000000..feff60d
--- /dev/null
+++ b/TODO
@@ -0,0 +1,5 @@
+ general:
+ - update TODO list
+ - colors                      0.8 - 1.0 ?
+ - custom fields               (partially done)
+
diff --git a/abook.1 b/abook.1
new file mode 100644 (file)
index 0000000..398ac7c
--- /dev/null
+++ b/abook.1
@@ -0,0 +1,84 @@
+.TH ABOOK 1 "March 18, 2000"
+.nh
+.SH NAME
+abook \- text-based address book program
+.SH SYNOPSIS
+.B abook
+[ \fB--help\fP | \fB--datafile\fP <filename> | \fB--mutt-query\fP <string> | \fB--convert\fP <inputformat> <inputfile> <outputformat> <outputfile> | \fB--add-email\fP | \fB--add-email-quiet\fP ] 
+.SH DESCRIPTION
+This manual page documents briefly the
+.B abook
+program.
+This manual page was written for the Debian GNU/Linux distribution
+because the original program does not have a manual page.
+.PP
+.B abook 
+is a text-based address book program. It contains Name, Email, Address 
+and various Phone fields. It is designed for use with mutt, but can be
+equally useful on its own.
+.SH OPTIONS
+.TP
+\fB\-\-help\fP
+Show usage.
+.TP
+\fB\-\-datafile\fP <filename>
+Use an alternative addressbook file (default is $HOME/.abook.addressbook).
+.TP
+\fB\-\-mutt-query\fP <string>
+Make a query for mutt (search the addressbook for <string>).
+.br
+The \fB\-\-datafile\fP option, as documented above, may be used BEFORE this
+option to search a different addressbook file.
+.TP
+\fB\-\-convert\fP <inputformat> <inputfile> <outputformat> <outputfile>
+Converts <inputfile> in <inputformat> to <outputfile> in <outputformat>
+
+.br
+The following \fBinputformats\fP are supported:
+.br
+- \fBabook\fP abook native format
+.br
+- \fBldif\fP ldif / Netscape addressbook
+.br
+- \fBpine\fP pine addressbook
+.br
+- \fBcsv\fP comma separated values
+
+.br
+The following \fBoutputformats\fP are supported:
+.br
+- \fBabook\fP abook native format
+.br
+- \fBmutt\fP mutt alias
+.br
+- \fBhtml\fP html document
+.br
+- \fBpine\fP pine addressbook
+.br
+- \fBgcrd\fP GnomeCard (VCard) addressbook
+.br
+- \fBcsv\fP comma separated values
+.br
+- \fBelm\fP elm alias
+.br
+- \fBtext\fP plain text
+.TP
+\fB\-\-add-email\fP
+Read an e-mail message from stdin and add the sender to the addressbook.
+.TP
+\fB\-\-add-email-quiet\fP
+Same as --add-email but doesn't confirm adding.
+
+.SH COMMANDS DURING USE
+Press '\fB?\fP' during use to get a list of commands.
+.SH SEE ALSO
+.BR mutt (1),
+.BR abookrc (5)
+.br
+.SH AUTHOR
+This manual page was written by Alan Ford <alan@whirlnet.co.uk>,
+for the Debian GNU/Linux system (but may be used by others).
+
+.br
+.B abook
+was written by Jaakko Heinonen <jheinonen@users.sourceforge.net>
diff --git a/abook.c b/abook.c
new file mode 100644 (file)
index 0000000..fdad05e
--- /dev/null
+++ b/abook.c
@@ -0,0 +1,602 @@
+/*
+ * $Id: abook.c,v 1.23 2002/02/04 13:41:25 jheinonen Exp $
+ *
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <fcntl.h>
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
+#      include <locale.h>
+#endif
+#include "abook.h"
+#include "ui.h"
+#include "database.h"
+#include "list.h"
+#include "filter.h"
+#include "edit.h"
+#include "misc.h"
+#include "options.h"
+#include "getname.h"
+
+static void             init_abook();
+static void             set_filenames();
+static void            free_filenames();
+static void             parse_command_line(int argc, char **argv);
+static void             show_usage();
+static void             mutt_query(char *str);
+static void             init_mutt_query();
+static void             quit_mutt_query();
+static void            convert(char *srcformat, char *srcfile,
+                               char *dstformat, char *dstfile);
+static void            add_email(int);
+
+char *datafile = NULL;
+char *rcfile = NULL;
+
+static void
+init_abook()
+{
+       set_filenames();
+       init_options();
+
+       signal(SIGKILL, quit_abook);
+       signal(SIGTERM, quit_abook);
+       
+       if( init_ui() )
+               exit(1);
+       
+       umask(DEFAULT_UMASK);
+
+       /*
+        * this is very ugly for now
+        */
+       /*if( options_get_int("datafile", "autosave") )*/
+
+       if( load_database(datafile) == 2 ) {
+               char *tmp = strconcat(getenv("HOME"),
+                               "/" DATAFILE, NULL);
+
+               if( safe_strcmp(tmp, datafile) ) {
+                       refresh_screen();
+                       statusline_msg("Sorry, the specified file does "
+                               "not appear to be a valid abook addressbook");
+                       statusline_msg("Will open default addressbook...");
+                       free(datafile);
+                       datafile = tmp;
+                       load_database(datafile);
+               } else
+                       free(tmp);
+       }
+
+       refresh_screen();
+}
+
+void
+quit_abook()
+{
+       if( options_get_int("autosave") )
+               save_database();
+       else if( statusline_ask_boolean("Save database", TRUE) )
+               save_database();
+
+       close_config();
+       close_database();
+
+       close_ui();
+       
+       exit(0);
+}
+
+int
+main(int argc, char **argv)
+{
+#if defined(HAVE_SETLOCALE) && defined(HAVE_LOCALE_H)
+       setlocale(LC_ALL, "" );
+#endif
+               
+       parse_command_line(argc, argv);
+       
+       init_abook();
+
+       get_commands(); 
+       
+       quit_abook();
+
+       return 0;
+}
+
+static void
+set_filenames()
+{
+       struct stat s;
+
+       if( (stat(getenv("HOME"), &s)) == -1 || ! S_ISDIR(s.st_mode) ) {
+               fprintf(stderr,"%s is not a valid HOME directory\n", getenv("HOME") );
+               exit(1);
+       }
+
+       if (!datafile)
+               datafile = strconcat(getenv("HOME"), "/" DATAFILE, NULL);
+
+       rcfile = strconcat(getenv("HOME"), "/" RCFILE, NULL);
+
+       atexit(free_filenames);
+}
+
+static void
+free_filenames()
+{
+       my_free(rcfile);
+       my_free(datafile);
+}
+
+static void
+parse_command_line(int argc, char **argv)
+{
+       int i;
+
+       for( i = 1; i < argc; i++ ) {
+               if( !strcmp(argv[i], "--help") ) {
+                       show_usage();
+                       exit(1);
+               } else if( !strcmp(argv[i], "--mutt-query") ) {
+                       mutt_query(argv[i + 1]);
+               } else if( !strcmp(argv[i], "--datafile") ) {
+                       if (argc > i + 1 ) {
+                               if (argv[i+1][0] != '/') {
+                                       char *cwd = my_getcwd();
+                                       datafile = strconcat(cwd, "/", argv[i+1], NULL);
+                                       free(cwd);
+                               } else {
+                                       datafile = strdup(argv[i+1]);
+                               }
+                               i++;
+                       } else {
+                               show_usage();
+                               exit(1);
+                       }
+               } else if( !strcmp(argv[i], "--convert") ) {
+                       if( argc < 5 || argc > 6 ) {
+                               fprintf(stderr, "incorrect number of argumets to make conversion\n");
+                               fprintf(stderr, "try %s --help\n", argv[0]);
+                               exit(1);
+                       }
+                       if( argc > i + 4 )
+                               convert(argv[i+1], argv[i+2],
+                                       argv[i+3], argv[i+4]);
+                       else
+                               convert(argv[i+1], argv[i+2], argv[i+3], "-");
+               } else if( !strcmp(argv[i], "--add-email") ) {
+                       add_email(0);
+               } else if( !strcmp(argv[i], "--add-email-quiet") ) {
+                       add_email(1);
+               } else {
+                       printf("option %s not recognized\n", argv[i]);
+                       printf("try %s --help\n", argv[0]);
+                       exit(1);
+               }
+       }
+}
+
+
+static void
+show_usage()
+{
+       puts    (PACKAGE " v " VERSION "\n");
+       puts    ("      --help                          show usage");
+       puts    ("      --datafile      <filename>      use an alternative addressbook file");
+       puts    ("      --mutt-query    <string>        make a query for mutt");
+       puts    ("      --convert       <inputformat> <inputfile> "
+               "<outputformat> <outputfile>");
+       puts    ("      --add-email                     "
+                       "read an e-mail message from stdin and\n"
+               "                                       "
+               "add the sender to the addressbook");
+       puts    ("      --add-email-quiet               "
+               "same as --add-email but doesn't\n"
+               "                                       confirm adding");
+       putchar('\n');
+       puts    ("available formats for --convert option:");
+       print_filters();
+#ifdef DEBUG
+       puts    ("\nWarning: this version compiled with DEBUG flag ON");
+#endif
+}
+
+extern list_item *database;
+
+static void
+muttq_print_item(FILE *file, int item)
+{
+       char emails[MAX_EMAILS][MAX_EMAIL_LEN];
+       int i;
+
+       split_emailstr(item, emails);
+       
+       for(i = 0; i < (options_get_int("mutt_return_all_emails") ?
+                       MAX_EMAILS : 1) ; i++)
+               if( *emails[i] )
+                       fprintf(file, "%s\t%s\t%s\n", emails[i],
+                               database[item][NAME],
+                               database[item][NOTES] == NULL ? " " :
+                                       database[item][NOTES]
+                               );
+}
+
+static void
+mutt_query(char *str)
+{
+       init_mutt_query();
+
+       if( str == NULL || !strcasecmp(str, "all") ) {
+               struct db_enumerator e = init_db_enumerator(ENUM_ALL);
+               printf("All items\n");
+               db_enumerate_items(e)
+                       muttq_print_item(stdout, e.item);
+       } else {
+               int search_fields[] = {NAME, EMAIL, NICK, -1};
+               int i;
+               if( (i = find_item(str, 0, search_fields)) < 0 ) {
+                       printf("Not found\n");
+                       quit_mutt_query(1);
+               }
+               putchar('\n');
+               while(i >= 0) {
+                       muttq_print_item(stdout, i);
+                       i = find_item(str, i+1, search_fields);
+               }
+       }
+
+       quit_mutt_query(0);
+}
+
+static void
+init_mutt_query()
+{
+       set_filenames();
+       init_options();
+       
+       if( load_database(datafile) ) {
+               printf("Cannot open database\n");
+               quit_mutt_query(1);
+               exit(1);
+       }
+}
+
+static void
+quit_mutt_query(int status)
+{
+       close_database();
+       close_config();
+
+       exit(status);
+}
+
+
+static char *
+make_mailstr(int item)
+{
+       char email[MAX_EMAIL_LEN];
+       char *ret;
+       char *name = mkstr("\"%s\"", database[item][NAME]);
+
+       get_first_email(email, item);
+
+       ret = *database[item][EMAIL] ?
+               mkstr("%s <%s>", name, email) :
+               strdup(name);
+
+       free(name);
+       
+       return ret;
+}
+
+void
+print_stderr(int item)
+{
+       fprintf (stderr, "%c", '\n');
+
+       if( is_valid_item(item) )
+               muttq_print_item(stderr, item);
+       else {
+               struct db_enumerator e = init_db_enumerator(ENUM_SELECTED);
+               db_enumerate_items(e) {
+                       muttq_print_item(stderr, e.item);
+               }
+       }
+
+}
+
+void
+launch_mutt(int item)
+{
+       char *cmd = NULL, *mailstr = NULL;
+       char *mutt_command = options_get_str("mutt_command");
+
+       if(mutt_command == NULL || !*mutt_command)
+               return;
+
+       if( is_valid_item(item) )
+               mailstr = make_mailstr(item);
+       else {
+               struct db_enumerator e = init_db_enumerator(ENUM_SELECTED);
+               char *tmp = NULL;
+               db_enumerate_items(e) {
+                       tmp = mailstr;
+                       mailstr = tmp ?
+                               strconcat(tmp, ",", make_mailstr(e.item), NULL):
+                               strconcat(make_mailstr(e.item), NULL);
+                       free(tmp);
+               }
+       }
+
+       cmd = strconcat(mutt_command, " \'", mailstr,
+                               "\'", NULL);
+       free(mailstr);
+#ifdef DEBUG
+       fprintf(stderr, "cmd: %s\n", cmd);
+#endif
+       system(cmd);    
+       free(cmd);
+       
+       /*
+        * we need to make sure that curses settings are correct
+        */
+       ui_init_curses();
+}
+
+void
+launch_wwwbrowser(int item)
+{
+       char *cmd = NULL;
+
+       if( !is_valid_item(item) )
+               return;
+
+       if( database[item][URL] )
+               cmd = mkstr("%s '%s'",
+                               options_get_str("www_command"),
+                               safe_str(database[item][URL]));
+       else
+               return;
+
+       if ( cmd )
+               system(cmd);
+
+       free(cmd);
+
+       /*
+        * we need to make sure that curses settings are correct
+        */
+       ui_init_curses();
+}
+
+void *
+abook_malloc(size_t size)
+{
+       void *ptr;
+
+       if ( (ptr = malloc(size)) == NULL ) {
+               if( is_ui_initialized() )
+                       quit_abook();
+               perror("malloc() failed");
+               exit(1);
+       }
+
+       return ptr;
+}
+
+void *
+abook_realloc(void *ptr, size_t size)
+{
+       ptr = realloc(ptr, size);
+
+       if( size == 0 )
+               return NULL;
+
+       if( ptr == NULL ) {
+               if( is_ui_initialized() )
+                       quit_abook();
+               perror("realloc() failed");
+               exit(1);
+       }
+
+       return ptr;
+}
+
+FILE *
+abook_fopen (const char *path, const char *mode)
+{      
+       struct stat s;
+       
+       if ( (stat(path, &s)) == -1 )
+               return NULL;
+
+       if(strchr(mode, 'r'))
+               return S_ISREG(s.st_mode) ? fopen(path, mode) : NULL;
+       else
+               return S_ISDIR(s.st_mode) ? NULL : fopen(path, mode);
+}
+
+
+
+static void
+convert(char *srcformat, char *srcfile, char *dstformat, char *dstfile)
+{
+       int ret=0;
+
+       if( !srcformat || !srcfile || !dstformat || !dstfile ) {
+               fprintf(stderr, "too few argumets to make conversion\n");
+               fprintf(stderr, "try --help\n");
+       }
+
+       strlower(srcformat);
+       strlower(dstformat);
+
+#ifndef DEBUG
+       if( !strcmp(srcformat, dstformat) ) {
+               printf( "input and output formats are the same\n"
+                       "exiting...\n");
+               exit(1);
+       }
+#endif
+
+       set_filenames();
+       init_options();
+
+       switch( import(srcformat, srcfile) ) {
+               case -1:
+                       fprintf(stderr,
+                               "input format %s not supported\n", srcformat);
+                       ret = 1;
+                       break;
+               case 1:
+                       fprintf(stderr, "cannot read file %s\n", srcfile);
+                       ret = 1;
+                       break;
+       }
+
+       if(!ret)
+               switch( export(dstformat, dstfile) ) {
+                       case -1:
+                               fprintf(stderr,
+                                       "output format %s not supported\n",
+                                       dstformat);
+                               ret = 1;
+                               break;
+                       case 1:
+                               fprintf(stderr,
+                                       "cannot write file %s\n", dstfile);
+                               ret = 1;
+                               break;
+               }
+
+       close_database();
+       close_config();
+       exit(ret);
+}
+
+/*
+ * --add-email handling
+ */
+
+static int add_email_count = 0;
+
+static void
+quit_add_email()
+{
+       if(add_email_count > 0) {
+               if(save_database() < 0) {
+                       fprintf(stderr, "cannot open %s\n", datafile);
+                       exit(1);
+               }
+               printf("%d item(s) added to %s\n", add_email_count, datafile);
+       } else {
+               puts("Valid sender address not found");
+       }
+
+       exit(0);
+}
+
+static void
+quit_add_email_sig(int signal)
+{
+       quit_add_email();
+}
+
+static void
+init_add_email()
+{
+       set_filenames();
+       atexit(free_filenames);
+       init_options();
+       atexit(close_config);
+       
+       /*
+        * we don't actually care if loading fails or not
+        */
+       load_database(datafile);
+
+       atexit(close_database);
+
+       signal(SIGINT, quit_add_email_sig);
+}
+
+static int
+add_email_add_item(int quiet, char *name, char *email)
+{
+       list_item item;
+
+       if(!quiet) {
+               FILE *in = fopen("/dev/tty", "r");
+               char c;
+               if(!in) {
+                       fprintf(stderr, "cannot open /dev/tty\n"
+                               "you may want to use --add-email-quiet\n");
+                       exit(1);
+               }
+               printf("Add ``%s <%s>'' to %s ? (y/n)\n",
+                               name,
+                               email,
+                               datafile
+               );
+               do {
+                       c = fgetc(in);
+                       if(c == 'n' || c == 'N') {
+                               fclose(in);
+                               return 0;
+                       }
+               } while(c != 'y' && c != 'Y');
+               fclose(in);
+       }
+
+       memset(item, 0, sizeof(item));
+       item[NAME] = strdup(name);
+       item[EMAIL] = strdup(email);
+       add_item2database(item);
+
+       return 1;
+}
+
+static void
+add_email(int quiet)
+{
+       char *line;
+       char *name = NULL, *email = NULL;
+       struct stat s;  
+
+       if( (fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode)) {
+               fprintf(stderr, "stdin is a directory or cannot stat stdin\n");
+               exit(1);
+       }
+
+       init_add_email();
+
+       do {
+               line = getaline(stdin);
+               if(line && !strncasecmp("From:", line, 5) ) {
+                       getname(line, &name, &email);
+                       add_email_count += add_email_add_item(quiet,
+                                       name, email);
+                       my_free(name);
+                       my_free(email);
+               }
+               my_free(line);
+       } while( !feof(stdin) );
+
+       quit_add_email();
+}
+
+/*
+ * end of --add-email handling
+ */
diff --git a/abook.h b/abook.h
new file mode 100644 (file)
index 0000000..8fa08cd
--- /dev/null
+++ b/abook.h
@@ -0,0 +1,56 @@
+#ifndef _ABOOK_H
+#define _ABOOK_H
+
+#include <stdio.h>
+
+void           *abook_malloc(size_t size);
+void           *abook_realloc(void *ptr, size_t size);
+FILE           *abook_fopen (const char *path, const char *mode);
+void           quit_abook();
+void           launch_wwwbrowser(int item);
+void           launch_mutt(int item);
+void           print_stderr(int item);
+#ifdef _AIX
+int            strcasecmp (const char *, const char *);
+int            strncasecmp (const char *, const char *, size_t);
+#endif
+
+#define MAIN_HELPLINE        "q:quit  ?:help  a:add  r:remove"
+
+#define Y_STATUSLINE           (LINES - 2)
+
+#define MIN_LINES      20      
+#define MIN_COLS       70      
+
+#define DEFAULT_UMASK  066
+#define DATAFILE       ".abook.addressbook"
+
+/*
+ * some "abookwide" useful macros
+ */
+
+#define hide_cursor()  curs_set(0)
+#define show_cursor()  curs_set(1)
+
+#define safe_atoi(X)    (X == NULL) ? 0 : atoi(X)
+#define my_free(X)     do {free(X); X=NULL;} while(0)
+#define safe_str(X)    X == NULL ? "" : X
+#define safe_strdup(X) (X == NULL) ? NULL : strdup(X)
+
+#ifndef min
+#       define min(x,y) (((x)<(y)) ? (x):(y))
+#endif
+
+#ifndef max
+#       define max(x,y) (((x)>(y)) ? (x):(y))
+#endif
+
+#define ISSPACE(c)     isspace((unsigned char)c)
+
+#ifndef DEBUG
+#      define NDEBUG   1
+#else
+#      undef NDEBUG
+#endif
+
+#endif
diff --git a/abook_curses.h b/abook_curses.h
new file mode 100644 (file)
index 0000000..94e0012
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef _ABOOK_CURSES_H
+#define _ABOOK_CURSES_H
+
+#include "config.h"
+
+#ifdef HAVE_NCURSES_H
+#      include <ncurses.h>
+#else
+#      include <curses.h>
+#endif
+
+#ifndef getnstr
+#      define getnstr(s, n)           wgetnstr(stdscr, s, n)
+#endif
+
+#endif
diff --git a/abookrc.5 b/abookrc.5
new file mode 100644 (file)
index 0000000..51ce9ac
--- /dev/null
+++ b/abookrc.5
@@ -0,0 +1,164 @@
+.TH ABOOKRC 5 "Jan 2, 2001"
+.nh
+.SH NAME
+\fB$HOME/.abookrc\fP \- configuration file for abook address book program
+.SH DESCRIPTION
+This manual page documents briefly the
+.B .abookrc
+file.
+.br
+.B .abookrc
+is the (optional) configuration file for use with the
+.B abook(1)
+address book program.
+
+.B .abookrc
+is stored in a user's $HOME directory. It follows a format of option=value.
+The following information lists each of these options and the values they
+may take.
+
+If a variable is not set in 
+.B .abookrc
+, a sensible default, as 
+listed with the description below, will be used.
+
+Comments in 
+.B .abookrc
+are on lines beginning with '#'.
+
+.SH VARIABLES
+
+.TP
+\fBautosave\fP=[true|false]
+Defines whether the addressbook is automatically saved on exit. Default is true.
+
+.TP
+\fBshow_all_emails\fP=[true|false]
+Defines whether all email addresses for a contact are shown in the main list view. Default is true
+
+.TP
+\fBemailpos\fP=column
+Defines the screen column on the main list where the email address is to begin. Default is 25.
+
+.TP
+\fBextra_column\fP=field
+Defines the variable to display in the extra (third) column on the main list. Default is "phone" (Home Phone).
+.br
+The following strings are used to represent commonly used \fIfield\fPs:
+.br
+-1                     disabled
+.br
+phone          Home Phone
+.br
+workphone              Work Phone
+.br
+fax                    Fax
+.br
+mobile         Mobile Phone
+.br
+nick                   Nick / Alias
+.br
+url                    URL
+.br
+notes          Notes
+
+.TP
+\fBextra_alternative\fP=field
+This is an optional setting that allows you to specify an alternative field to be displayed in the extra (third) column if there is no data for the field specified in extra_column for a particular item. The strings for the fields are the same as above. Please note that the data shown where the alternative field has been used will NOT be marked differently in any way from the rest of the extra column. There is no default.
+
+.TP
+\fBextrapos\fP=column
+Defines the screen column on the main list where the extra field is to begin. Default is 65.
+
+.TP
+\fBmutt_command\fP=command
+Defines the command to start mutt. Default is "mutt".
+
+.TP
+\fBmutt_return_all_emails\fP=[true|false]
+Defines whether to return all email addresses matching the search criteria to a mutt query. Default is true.
+
+.TP
+\fBprint_command\fP=command
+Defines the command to used when printing the addressbook. Default is "lpr".
+
+.TP
+\fBfilesel_sort\fP=[true|false]
+Defines whether to sort the files in the fileselector in alphabetical order. Default is false.
+
+.TP
+\fBwww_command\fP=command
+Defines the command used to start the web browser to view a contact's URL. Default is "lynx".
+
+.TP
+\fBaddress_style\fP=[eu|uk|us]
+Defines the style of address formatting to be used when exporting as text / printing the database (European, UK, or USA). Default is European ("eu").
+
+.TP
+\fBuse_ascii_only\fP=[true|false]
+This option allows you to force Abook use only ASCII characters. This option is useful if your terminal doesn't support non-ASCII characters. Default is false.
+
+.SH SAMPLE CONFIGURATION FILE
+
+.nf
+# sample abook configuration file
+#
+
+# Automatically save database on exit
+autosave=true
+
+# Show all email addresses in list
+show_all_emails=true
+
+# Screen column for email field to start
+emailpos=25
+
+# Field to be used in the extra column
+extra_column=phone
+# frequently used values:
+#      -1              disabled
+#      phone           Home Phone
+#      workphone       Work Phone
+#      fax             Fax
+#      mobile          Mobile Phone
+#      nick            Nick / Alias
+#      url             URL
+
+#
+extra_alternative=-1
+
+# Screen column for the extra field to start
+extrapos=65
+
+# Command used to start mutt
+mutt_command=mutt
+
+# Return all email addresses to a mutt query
+mutt_return_all_emails=true
+
+# Command used to print
+print_command=lpr
+
+# Sort files in fileselector (alphabetic order)
+filesel_sort=false
+
+# Command used to start the web browser
+www_command=lynx
+
+# address style [eu|us|uk]
+address_style=eu
+
+# use ASCII characters only
+use_ascii_only=false
+
+.fi
+
+.SH SEE ALSO
+.BR abook (1).
+.br
+.SH AUTHOR
+This manual page was written by Alan Ford <alan@whirlnet.co.uk>.
+
+.br
+.B abook
+was written by Jaakko Heinonen <jheinonen@users.sourceforge.net>
diff --git a/acconfig.h b/acconfig.h
new file mode 100644 (file)
index 0000000..c40c52d
--- /dev/null
@@ -0,0 +1,11 @@
+#undef VERSION
+#undef PACKAGE
+
+/* Define if you have the <stdarg.h> header file.  */
+#undef HAVE_STDARG_H
+
+/* Define if you have the <ncurses.h> header file.  */
+#undef HAVE_NCURSES_H
+
+#undef HAVE_SNPRINTF
+#undef HAVE_VSNPRINTF
diff --git a/acinclude.m4 b/acinclude.m4
new file mode 100644 (file)
index 0000000..5d443ec
--- /dev/null
@@ -0,0 +1,83 @@
+dnl ---------------------------------------------------------------------------
+dnl Look for the curses libraries.  Older curses implementations may require
+dnl termcap/termlib to be linked as well.
+AC_DEFUN([CF_CURSES_LIBS],[
+AC_CHECK_FUNC(initscr,,[
+case $host_os in #(vi
+freebsd*) #(vi
+       AC_CHECK_LIB(mytinfo,tgoto,[LIBS="-lmytinfo $LIBS"])
+       ;;
+hpux10.*|hpux11.*)
+       AC_CHECK_LIB(cur_colr,initscr,[
+               LIBS="-lcur_colr $LIBS"
+               CFLAGS="-I/usr/include/curses_colr $CFLAGS"
+               ac_cv_func_initscr=yes
+               ],[
+       AC_CHECK_LIB(Hcurses,initscr,[
+               # HP's header uses __HP_CURSES, but user claims _HP_CURSES.
+               LIBS="-lHcurses $LIBS"
+               CFLAGS="-D__HP_CURSES -D_HP_CURSES $CFLAGS"
+               ac_cv_func_initscr=yes
+               ])])
+       ;;
+linux*) # Suse Linux does not follow /usr/lib convention
+       LIBS="$LIBS -L/lib"
+       ;;
+esac
+
+if test ".$With5lib" != ".no" ; then
+if test -d /usr/5lib ; then
+       # SunOS 3.x or 4.x
+       CPPFLAGS="$CPPFLAGS -I/usr/5include"
+       LIBS="$LIBS -L/usr/5lib"
+fi
+fi
+
+if test ".$ac_cv_func_initscr" != .yes ; then
+       cf_save_LIBS="$LIBS"
+       cf_term_lib=""
+       cf_curs_lib=""
+
+       # Check for library containing tgoto.  Do this before curses library
+       # because it may be needed to link the test-case for initscr.
+       AC_CHECK_FUNC(tgoto,[cf_term_lib=predefined],[
+               for cf_term_lib in termcap termlib unknown
+               do
+                       AC_CHECK_LIB($cf_term_lib,tgoto,[break])
+               done
+       ])
+
+       # Check for library containing initscr
+       test "$cf_term_lib" != predefined && test "$cf_term_lib" != unknown && LIBS="-l$cf_term_lib $cf_save_LIBS"
+       for cf_curs_lib in cursesX curses ncurses xcurses jcurses unknown
+       do
+               AC_CHECK_LIB($cf_curs_lib,initscr,[break])
+       done
+       test $cf_curs_lib = unknown && AC_ERROR(no curses library found)
+
+       LIBS="-l$cf_curs_lib $cf_save_LIBS"
+       if test "$cf_term_lib" = unknown ; then
+               AC_MSG_CHECKING(if we can link with $cf_curs_lib library)
+               AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
+                       [initscr()],
+                       [cf_result=yes],
+                       [cf_result=no])
+               AC_MSG_RESULT($cf_result)
+               test $cf_result = no && AC_ERROR(Cannot link curses library)
+       elif test "$cf_term_lib" != predefined ; then
+               AC_MSG_CHECKING(if we need both $cf_curs_lib and $cf_term_lib libraries)
+               AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
+                       [initscr(); tgoto((char *)0, 0, 0);],
+                       [cf_result=no],
+                       [
+                       LIBS="-l$cf_curs_lib -l$cf_term_lib $cf_save_LIBS"
+                       AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
+                               [initscr()],
+                               [cf_result=yes],
+                               [cf_result=error])
+                       ])
+               AC_MSG_RESULT($cf_result)
+       fi
+fi
+
+])])
diff --git a/aclocal.m4 b/aclocal.m4
new file mode 100644 (file)
index 0000000..0df26c7
--- /dev/null
@@ -0,0 +1,339 @@
+dnl aclocal.m4 generated automatically by aclocal 1.4-p5
+
+dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+dnl PARTICULAR PURPOSE.
+
+dnl ---------------------------------------------------------------------------
+dnl Look for the curses libraries.  Older curses implementations may require
+dnl termcap/termlib to be linked as well.
+AC_DEFUN([CF_CURSES_LIBS],[
+AC_CHECK_FUNC(initscr,,[
+case $host_os in #(vi
+freebsd*) #(vi
+       AC_CHECK_LIB(mytinfo,tgoto,[LIBS="-lmytinfo $LIBS"])
+       ;;
+hpux10.*|hpux11.*)
+       AC_CHECK_LIB(cur_colr,initscr,[
+               LIBS="-lcur_colr $LIBS"
+               CFLAGS="-I/usr/include/curses_colr $CFLAGS"
+               ac_cv_func_initscr=yes
+               ],[
+       AC_CHECK_LIB(Hcurses,initscr,[
+               # HP's header uses __HP_CURSES, but user claims _HP_CURSES.
+               LIBS="-lHcurses $LIBS"
+               CFLAGS="-D__HP_CURSES -D_HP_CURSES $CFLAGS"
+               ac_cv_func_initscr=yes
+               ])])
+       ;;
+linux*) # Suse Linux does not follow /usr/lib convention
+       LIBS="$LIBS -L/lib"
+       ;;
+esac
+
+if test ".$With5lib" != ".no" ; then
+if test -d /usr/5lib ; then
+       # SunOS 3.x or 4.x
+       CPPFLAGS="$CPPFLAGS -I/usr/5include"
+       LIBS="$LIBS -L/usr/5lib"
+fi
+fi
+
+if test ".$ac_cv_func_initscr" != .yes ; then
+       cf_save_LIBS="$LIBS"
+       cf_term_lib=""
+       cf_curs_lib=""
+
+       # Check for library containing tgoto.  Do this before curses library
+       # because it may be needed to link the test-case for initscr.
+       AC_CHECK_FUNC(tgoto,[cf_term_lib=predefined],[
+               for cf_term_lib in termcap termlib unknown
+               do
+                       AC_CHECK_LIB($cf_term_lib,tgoto,[break])
+               done
+       ])
+
+       # Check for library containing initscr
+       test "$cf_term_lib" != predefined && test "$cf_term_lib" != unknown && LIBS="-l$cf_term_lib $cf_save_LIBS"
+       for cf_curs_lib in cursesX curses ncurses xcurses jcurses unknown
+       do
+               AC_CHECK_LIB($cf_curs_lib,initscr,[break])
+       done
+       test $cf_curs_lib = unknown && AC_ERROR(no curses library found)
+
+       LIBS="-l$cf_curs_lib $cf_save_LIBS"
+       if test "$cf_term_lib" = unknown ; then
+               AC_MSG_CHECKING(if we can link with $cf_curs_lib library)
+               AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
+                       [initscr()],
+                       [cf_result=yes],
+                       [cf_result=no])
+               AC_MSG_RESULT($cf_result)
+               test $cf_result = no && AC_ERROR(Cannot link curses library)
+       elif test "$cf_term_lib" != predefined ; then
+               AC_MSG_CHECKING(if we need both $cf_curs_lib and $cf_term_lib libraries)
+               AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
+                       [initscr(); tgoto((char *)0, 0, 0);],
+                       [cf_result=no],
+                       [
+                       LIBS="-l$cf_curs_lib -l$cf_term_lib $cf_save_LIBS"
+                       AC_TRY_LINK([#include <${cf_cv_ncurses_header-curses.h}>],
+                               [initscr()],
+                               [cf_result=yes],
+                               [cf_result=error])
+                       ])
+               AC_MSG_RESULT($cf_result)
+       fi
+fi
+
+])])
+
+# Do all the work for Automake.  This macro actually does too much --
+# some checks are only needed if your package does certain things.
+# But this isn't really a big deal.
+
+# serial 1
+
+dnl Usage:
+dnl AM_INIT_AUTOMAKE(package,version, [no-define])
+
+AC_DEFUN([AM_INIT_AUTOMAKE],
+[AC_REQUIRE([AC_PROG_INSTALL])
+PACKAGE=[$1]
+AC_SUBST(PACKAGE)
+VERSION=[$2]
+AC_SUBST(VERSION)
+dnl test to see if srcdir already configured
+if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
+  AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
+fi
+ifelse([$3],,
+AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
+AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package]))
+AC_REQUIRE([AM_SANITY_CHECK])
+AC_REQUIRE([AC_ARG_PROGRAM])
+dnl FIXME This is truly gross.
+missing_dir=`cd $ac_aux_dir && pwd`
+AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
+AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
+AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
+AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
+AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
+AC_REQUIRE([AC_PROG_MAKE_SET])])
+
+#
+# Check to make sure that the build environment is sane.
+#
+
+AC_DEFUN([AM_SANITY_CHECK],
+[AC_MSG_CHECKING([whether build environment is sane])
+# Just in case
+sleep 1
+echo timestamp > conftestfile
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
+   if test "[$]*" = "X"; then
+      # -L didn't work.
+      set X `ls -t $srcdir/configure conftestfile`
+   fi
+   if test "[$]*" != "X $srcdir/configure conftestfile" \
+      && test "[$]*" != "X conftestfile $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
+alias in your environment])
+   fi
+
+   test "[$]2" = conftestfile
+   )
+then
+   # Ok.
+   :
+else
+   AC_MSG_ERROR([newly created file is older than distributed files!
+Check your system clock])
+fi
+rm -f conftest*
+AC_MSG_RESULT(yes)])
+
+dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
+dnl The program must properly implement --version.
+AC_DEFUN([AM_MISSING_PROG],
+[AC_MSG_CHECKING(for working $2)
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf.  Sigh.
+if ($2 --version) < /dev/null > /dev/null 2>&1; then
+   $1=$2
+   AC_MSG_RESULT(found)
+else
+   $1="$3/missing $2"
+   AC_MSG_RESULT(missing)
+fi
+AC_SUBST($1)])
+
+# Like AC_CONFIG_HEADER, but automatically create stamp file.
+
+AC_DEFUN([AM_CONFIG_HEADER],
+[AC_PREREQ([2.12])
+AC_CONFIG_HEADER([$1])
+dnl When config.status generates a header, we must update the stamp-h file.
+dnl This file resides in the same directory as the config header
+dnl that is generated.  We must strip everything past the first ":",
+dnl and everything past the last "/".
+AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl
+ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>,
+<<test -z "<<$>>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>,
+<<am_indx=1
+for am_file in <<$1>>; do
+  case " <<$>>CONFIG_HEADERS " in
+  *" <<$>>am_file "*<<)>>
+    echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx
+    ;;
+  esac
+  am_indx=`expr "<<$>>am_indx" + 1`
+done<<>>dnl>>)
+changequote([,]))])
+
+#serial 1
+# This test replaces the one in autoconf.
+# Currently this macro should have the same name as the autoconf macro
+# because gettext's gettext.m4 (distributed in the automake package)
+# still uses it.  Otherwise, the use in gettext.m4 makes autoheader
+# give these diagnostics:
+#   configure.in:556: AC_TRY_COMPILE was called before AC_ISC_POSIX
+#   configure.in:556: AC_TRY_RUN was called before AC_ISC_POSIX
+
+undefine([AC_ISC_POSIX])
+
+AC_DEFUN([AC_ISC_POSIX],
+  [
+    dnl This test replaces the obsolescent AC_ISC_POSIX kludge.
+    AC_CHECK_LIB(cposix, strerror, [LIBS="$LIBS -lcposix"])
+  ]
+)
+
+
+# serial 1
+
+AC_DEFUN([AM_C_PROTOTYPES],
+[AC_REQUIRE([AM_PROG_CC_STDC])
+AC_REQUIRE([AC_PROG_CPP])
+AC_MSG_CHECKING([for function prototypes])
+if test "$am_cv_prog_cc_stdc" != no; then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(PROTOTYPES,1,[Define if compiler has function prototypes])
+  U= ANSI2KNR=
+else
+  AC_MSG_RESULT(no)
+  U=_ ANSI2KNR=./ansi2knr
+  # Ensure some checks needed by ansi2knr itself.
+  AC_HEADER_STDC
+  AC_CHECK_HEADERS(string.h)
+fi
+AC_SUBST(U)dnl
+AC_SUBST(ANSI2KNR)dnl
+])
+
+
+# serial 1
+
+# @defmac AC_PROG_CC_STDC
+# @maindex PROG_CC_STDC
+# @ovindex CC
+# If the C compiler in not in ANSI C mode by default, try to add an option
+# to output variable @code{CC} to make it so.  This macro tries various
+# options that select ANSI C on some system or another.  It considers the
+# compiler to be in ANSI C mode if it handles function prototypes correctly.
+#
+# If you use this macro, you should check after calling it whether the C
+# compiler has been set to accept ANSI C; if not, the shell variable
+# @code{am_cv_prog_cc_stdc} is set to @samp{no}.  If you wrote your source
+# code in ANSI C, you can make an un-ANSIfied copy of it by using the
+# program @code{ansi2knr}, which comes with Ghostscript.
+# @end defmac
+
+AC_DEFUN([AM_PROG_CC_STDC],
+[AC_REQUIRE([AC_PROG_CC])
+AC_BEFORE([$0], [AC_C_INLINE])
+AC_BEFORE([$0], [AC_C_CONST])
+dnl Force this before AC_PROG_CPP.  Some cpp's, eg on HPUX, require
+dnl a magic option to avoid problems with ANSI preprocessor commands
+dnl like #elif.
+dnl FIXME: can't do this because then AC_AIX won't work due to a
+dnl circular dependency.
+dnl AC_BEFORE([$0], [AC_PROG_CPP])
+AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C)
+AC_CACHE_VAL(am_cv_prog_cc_stdc,
+[am_cv_prog_cc_stdc=no
+ac_save_CC="$CC"
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX                  -qlanglvl=ansi
+# Ultrix and OSF/1     -std1
+# HP-UX                        -Aa -D_HPUX_SOURCE
+# SVR4                 -Xc -D__EXTENSIONS__
+for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  AC_TRY_COMPILE(
+[#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+], [
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+],
+[am_cv_prog_cc_stdc="$ac_arg"; break])
+done
+CC="$ac_save_CC"
+])
+if test -z "$am_cv_prog_cc_stdc"; then
+  AC_MSG_RESULT([none needed])
+else
+  AC_MSG_RESULT($am_cv_prog_cc_stdc)
+fi
+case "x$am_cv_prog_cc_stdc" in
+  x|xno) ;;
+  *) CC="$CC $am_cv_prog_cc_stdc" ;;
+esac
+])
+
diff --git a/conff.c b/conff.c
new file mode 100644 (file)
index 0000000..da000f1
--- /dev/null
+++ b/conff.c
@@ -0,0 +1,207 @@
+
+/*
+ *
+ * $Id: conff.c,v 1.5 2001/12/19 20:20:55 jheinonen Exp $
+ *
+ * Copyright (C) Jaakko Heinonen
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+#include "misc.h"
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+#include "conff.h"
+
+#ifndef DEBUG
+#      define NDEBUG   1
+#else
+#      undef NDEBUG
+#endif
+
+#include <assert.h>
+
+#ifdef _AIX
+int strcasecmp (const char *, const char *);
+int strncasecmp (const char *, const char *, size_t);
+#endif
+
+#define COMMENT_CHAR   '#'
+
+static void
+conff_free_node(struct conff_node *node)
+{
+       free(node -> value);
+       free(node -> key);
+       free(node);
+}
+
+/*
+ * conff_add_key
+ *
+ * returns 0 if the key was successfully added
+ */
+
+int
+conff_add_key(struct conff_node **ptr, char *key, char *value, int flags)
+{
+       struct conff_node *new_item, *next = NULL;
+       int replace = 0;
+
+       assert(key != NULL && value != NULL);
+
+       for(; *ptr; ptr = &( (*ptr) -> next) ) 
+               if(!strcasecmp(key, (*ptr) -> key ) ) {
+                       if (flags & REPLACE_KEY) {
+                               replace = 1;
+                               break;
+                       } else
+                               return 1;
+               }
+       
+       if( (new_item = malloc(sizeof(struct conff_node))) == NULL )
+               return 5;
+
+       if(replace) { 
+               next = (*ptr) -> next;
+               conff_free_node(*ptr);
+       }
+
+       new_item -> key = strdup(key);
+       new_item -> value = strdup(value);
+       new_item -> next = next;
+
+       *ptr = new_item;
+
+       return 0;
+}
+
+char *
+conff_get_value(struct conff_node *node, char *key)
+{
+
+       assert(key != NULL);
+       
+       for(; node ; node = node -> next) {
+               if(!strcasecmp(node -> key, key))
+                       return node -> value;
+       }
+
+       return NULL; /* not found */
+}
+
+void
+conff_free_nodes(struct conff_node *node)
+{
+       if(node != NULL) {
+               conff_free_nodes( node -> next );
+               conff_free_node( node );
+       }
+}
+
+#ifdef DEBUG
+void
+print_values(struct conff_node *node)
+{
+        for(;node; node = node -> next)
+               fprintf(stderr, "%s - %s\n", node -> key, node -> value);
+}
+#endif
+
+void
+conff_remove_key(struct conff_node **node, char *key)
+{
+       assert(key != NULL);
+       
+       for(; *node; node = &((*node) -> next) ) {
+               if(!strcasecmp(key, (*node) -> key ) ) {
+                       struct conff_node *tmp = *node;
+                       *node = (*node) -> next;
+                       conff_free_node(tmp);
+                       return;
+               }
+       }
+}
+
+int
+conff_save_file(struct conff_node *node, char *filename)
+{
+       FILE *out;
+
+       assert(filename != NULL);
+
+       if (!(out = fopen(filename, "w")))
+               return -1;
+
+       for(; node; node = node -> next)
+               fprintf(out, "%s=%s\n", node -> key, node -> value);
+
+       fputc('\n', out);
+       fclose(out);
+
+       return 0;
+}
+
+int
+conff_load_file(struct conff_node **node, char *filename, int flags)
+{
+       FILE *in;
+       char *line = NULL, *tmp;
+       int i = 0;
+
+       assert(filename != NULL);
+
+       if (!(in = fopen(filename, "r")))
+               return -1;
+
+       for(;;) {
+               i++;
+
+               line = getaline(in);
+               if( feof(in) )
+                       break;
+               if(!line)
+                       continue;
+
+               strtrim(line);
+
+               if(*line == '\n' || *line == '\0' || *line == COMMENT_CHAR) {
+                       free(line);
+                       continue;
+               }
+
+               if ( (tmp = strchr(line, '=') )) {
+                       *tmp++ = 0;
+                       conff_add_key(node, strtrim(line), strtrim(tmp), flags);
+               } else {
+/*                      fprintf(stderr, "parse error2,line #%d\n",i);*/
+                       fclose(in);
+                       free(line);
+                       return i;
+               }
+               free(line);
+       }
+
+       free(line);
+       fclose(in);
+
+       return 0;
+}
+
diff --git a/conff.h b/conff.h
new file mode 100644 (file)
index 0000000..31d563f
--- /dev/null
+++ b/conff.h
@@ -0,0 +1,54 @@
+
+/*
+ *
+ *  $Id: conff.h,v 1.3 2001/12/19 20:20:55 jheinonen Exp $
+ *
+ *  Copyright (C) Jaakko Heinonen
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _CONFF_H
+#define _CONFF_H
+
+#include <stdlib.h>
+
+
+struct conff_node
+{
+       char *key, *value;
+
+       struct conff_node *next;
+};
+
+
+int            conff_add_key(struct conff_node **ptr, char *key,
+               char *value, int flags);
+char           *conff_get_value(struct conff_node *node, char *key);
+#ifdef DEBUG
+void           print_values(struct conff_node *root);
+#endif
+void           conff_free_nodes(struct conff_node *node);
+void           conff_remove_key(struct conff_node **node, char *key);
+int            conff_save_file(struct conff_node *node, char *filename);
+int            conff_load_file(struct conff_node **node,
+               char *filename, int flags);
+char           *strtrim(char *);
+
+
+#define DONT_REPLACE_KEY       0
+#define REPLACE_KEY            1
+
+#endif
diff --git a/config.guess b/config.guess
new file mode 100644 (file)
index 0000000..0ce538b
--- /dev/null
@@ -0,0 +1,1183 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
+#   Free Software Foundation, Inc.
+#
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Written by Per Bothner <bothner@cygnus.com>.
+# Please send patches to <config-patches@gnu.org>.
+#
+# This script attempts to guess a canonical system name similar to
+# config.sub.  If it succeeds, it prints the system name on stdout, and
+# exits with 0.  Otherwise, it exits with 1.
+#
+# The plan is that this can be called by configure scripts if you
+# don't specify an explicit system type (host/target name).
+#
+# Only a few systems have been added to this list; please add others
+# (but try to keep the structure clean).
+#
+
+# Use $HOST_CC if defined. $CC may point to a cross-compiler
+if test x"$CC_FOR_BUILD" = x; then
+  if test x"$HOST_CC" != x; then
+    CC_FOR_BUILD="$HOST_CC"
+  else
+    if test x"$CC" != x; then
+      CC_FOR_BUILD="$CC"
+    else
+      CC_FOR_BUILD=cc
+    fi
+  fi
+fi
+
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 8/24/94.)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+       PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+dummy=dummy-$$
+trap 'rm -f $dummy.c $dummy.o $dummy; exit 1' 1 2 15
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+    *:NetBSD:*:*)
+       # Netbsd (nbsd) targets should (where applicable) match one or
+       # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
+       # *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
+       # switched to ELF, *-*-netbsd* would select the old
+       # object file format.  This provides both forward
+       # compatibility and a consistent mechanism for selecting the
+       # object file format.
+       # Determine the machine/vendor (is the vendor relevant).
+       case "${UNAME_MACHINE}" in
+           amiga) machine=m68k-cbm ;;
+           arm32) machine=arm-unknown ;;
+           atari*) machine=m68k-atari ;;
+           sun3*) machine=m68k-sun ;;
+           mac68k) machine=m68k-apple ;;
+           macppc) machine=powerpc-apple ;;
+           hp3[0-9][05]) machine=m68k-hp ;;
+           ibmrt|romp-ibm) machine=romp-ibm ;;
+           *) machine=${UNAME_MACHINE}-unknown ;;
+       esac
+       # The Operating System including object format.
+       if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+               | grep __ELF__ >/dev/null
+       then
+           # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+           # Return netbsd for either.  FIX?
+           os=netbsd
+       else
+           os=netbsdelf
+       fi
+       # The OS release
+       release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+       # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+       # contains redundant information, the shorter form:
+       # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+       echo "${machine}-${os}${release}"
+       exit 0 ;;
+    alpha:OSF1:*:*)
+       if test $UNAME_RELEASE = "V4.0"; then
+               UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+       fi
+       # A Vn.n version is a released version.
+       # A Tn.n version is a released field test version.
+       # A Xn.n version is an unreleased experimental baselevel.
+       # 1.2 uses "1.2" for uname -r.
+       cat <<EOF >$dummy.s
+       .data
+\$Lformat:
+       .byte 37,100,45,37,120,10,0     # "%d-%x\n"
+
+       .text
+       .globl main
+       .align 4
+       .ent main
+main:
+       .frame \$30,16,\$26,0
+       ldgp \$29,0(\$27)
+       .prologue 1
+       .long 0x47e03d80 # implver \$0
+       lda \$2,-1
+       .long 0x47e20c21 # amask \$2,\$1
+       lda \$16,\$Lformat
+       mov \$0,\$17
+       not \$1,\$18
+       jsr \$26,printf
+       ldgp \$29,0(\$26)
+       mov 0,\$16
+       jsr \$26,exit
+       .end main
+EOF
+       $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
+       if test "$?" = 0 ; then
+               case `./$dummy` in
+                       0-0)
+                               UNAME_MACHINE="alpha"
+                               ;;
+                       1-0)
+                               UNAME_MACHINE="alphaev5"
+                               ;;
+                       1-1)
+                               UNAME_MACHINE="alphaev56"
+                               ;;
+                       1-101)
+                               UNAME_MACHINE="alphapca56"
+                               ;;
+                       2-303)
+                               UNAME_MACHINE="alphaev6"
+                               ;;
+                       2-307)
+                               UNAME_MACHINE="alphaev67"
+                               ;;
+               esac
+       fi
+       rm -f $dummy.s $dummy
+       echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+       exit 0 ;;
+    Alpha\ *:Windows_NT*:*)
+       # How do we know it's Interix rather than the generic POSIX subsystem?
+       # Should we change UNAME_MACHINE based on the output of uname instead
+       # of the specific Alpha model?
+       echo alpha-pc-interix
+       exit 0 ;;
+    21064:Windows_NT:50:3)
+       echo alpha-dec-winnt3.5
+       exit 0 ;;
+    Amiga*:UNIX_System_V:4.0:*)
+       echo m68k-cbm-sysv4
+       exit 0;;
+    amiga:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    *:[Aa]miga[Oo][Ss]:*:*)
+       echo ${UNAME_MACHINE}-unknown-amigaos
+       exit 0 ;;
+    arc64:OpenBSD:*:*)
+       echo mips64el-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    arc:OpenBSD:*:*)
+       echo mipsel-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    hkmips:OpenBSD:*:*)
+       echo mips-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    pmax:OpenBSD:*:*)
+       echo mipsel-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    sgi:OpenBSD:*:*)
+       echo mips-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    wgrisc:OpenBSD:*:*)
+       echo mipsel-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    *:OS/390:*:*)
+       echo i370-ibm-openedition
+       exit 0 ;;
+    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+       echo arm-acorn-riscix${UNAME_RELEASE}
+       exit 0;;
+    SR2?01:HI-UX/MPP:*:*)
+       echo hppa1.1-hitachi-hiuxmpp
+       exit 0;;
+    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+       # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+       if test "`(/bin/universe) 2>/dev/null`" = att ; then
+               echo pyramid-pyramid-sysv3
+       else
+               echo pyramid-pyramid-bsd
+       fi
+       exit 0 ;;
+    NILE*:*:*:dcosx)
+       echo pyramid-pyramid-svr4
+       exit 0 ;;
+    sun4H:SunOS:5.*:*)
+       echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+       echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    i86pc:SunOS:5.*:*)
+       echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    sun4*:SunOS:6*:*)
+       # According to config.sub, this is the proper way to canonicalize
+       # SunOS6.  Hard to guess exactly what SunOS6 will be like, but
+       # it's likely to be more like Solaris than SunOS4.
+       echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    sun4*:SunOS:*:*)
+       case "`/usr/bin/arch -k`" in
+           Series*|S4*)
+               UNAME_RELEASE=`uname -v`
+               ;;
+       esac
+       # Japanese Language versions have a version number like `4.1.3-JL'.
+       echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+       exit 0 ;;
+    sun3*:SunOS:*:*)
+       echo m68k-sun-sunos${UNAME_RELEASE}
+       exit 0 ;;
+    sun*:*:4.2BSD:*)
+       UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+       test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+       case "`/bin/arch`" in
+           sun3)
+               echo m68k-sun-sunos${UNAME_RELEASE}
+               ;;
+           sun4)
+               echo sparc-sun-sunos${UNAME_RELEASE}
+               ;;
+       esac
+       exit 0 ;;
+    aushp:SunOS:*:*)
+       echo sparc-auspex-sunos${UNAME_RELEASE}
+       exit 0 ;;
+    atari*:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    # The situation for MiNT is a little confusing.  The machine name
+    # can be virtually everything (everything which is not
+    # "atarist" or "atariste" at least should have a processor
+    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
+    # to the lowercase version "mint" (or "freemint").  Finally
+    # the system name "TOS" denotes a system which is actually not
+    # MiNT.  But MiNT is downward compatible to TOS, so this should
+    # be no problem.
+    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+       exit 0 ;;
+    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+       echo m68k-atari-mint${UNAME_RELEASE}
+        exit 0 ;;
+    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+       exit 0 ;;
+    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+        echo m68k-milan-mint${UNAME_RELEASE}
+        exit 0 ;;
+    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+        echo m68k-hades-mint${UNAME_RELEASE}
+        exit 0 ;;
+    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+        echo m68k-unknown-mint${UNAME_RELEASE}
+        exit 0 ;;
+    sun3*:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    mac68k:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    mvme68k:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    mvme88k:OpenBSD:*:*)
+       echo m88k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    powerpc:machten:*:*)
+       echo powerpc-apple-machten${UNAME_RELEASE}
+       exit 0 ;;
+    RISC*:Mach:*:*)
+       echo mips-dec-mach_bsd4.3
+       exit 0 ;;
+    RISC*:ULTRIX:*:*)
+       echo mips-dec-ultrix${UNAME_RELEASE}
+       exit 0 ;;
+    VAX*:ULTRIX*:*:*)
+       echo vax-dec-ultrix${UNAME_RELEASE}
+       exit 0 ;;
+    2020:CLIX:*:* | 2430:CLIX:*:*)
+       echo clipper-intergraph-clix${UNAME_RELEASE}
+       exit 0 ;;
+    mips:*:*:UMIPS | mips:*:*:RISCos)
+       sed 's/^        //' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+       int main (int argc, char *argv[]) {
+#else
+       int main (argc, argv) int argc; char *argv[]; {
+#endif
+       #if defined (host_mips) && defined (MIPSEB)
+       #if defined (SYSTYPE_SYSV)
+         printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+       #endif
+       #if defined (SYSTYPE_SVR4)
+         printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+       #endif
+       #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+         printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+       #endif
+       #endif
+         exit (-1);
+       }
+EOF
+       $CC_FOR_BUILD $dummy.c -o $dummy \
+         && ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
+         && rm $dummy.c $dummy && exit 0
+       rm -f $dummy.c $dummy
+       echo mips-mips-riscos${UNAME_RELEASE}
+       exit 0 ;;
+    Night_Hawk:Power_UNIX:*:*)
+       echo powerpc-harris-powerunix
+       exit 0 ;;
+    m88k:CX/UX:7*:*)
+       echo m88k-harris-cxux7
+       exit 0 ;;
+    m88k:*:4*:R4*)
+       echo m88k-motorola-sysv4
+       exit 0 ;;
+    m88k:*:3*:R3*)
+       echo m88k-motorola-sysv3
+       exit 0 ;;
+    AViiON:dgux:*:*)
+        # DG/UX returns AViiON for all architectures
+        UNAME_PROCESSOR=`/usr/bin/uname -p`
+       if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+       then
+           if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+              [ ${TARGET_BINARY_INTERFACE}x = x ]
+           then
+               echo m88k-dg-dgux${UNAME_RELEASE}
+           else
+               echo m88k-dg-dguxbcs${UNAME_RELEASE}
+           fi
+       else
+           echo i586-dg-dgux${UNAME_RELEASE}
+       fi
+       exit 0 ;;
+    M88*:DolphinOS:*:*)        # DolphinOS (SVR3)
+       echo m88k-dolphin-sysv3
+       exit 0 ;;
+    M88*:*:R3*:*)
+       # Delta 88k system running SVR3
+       echo m88k-motorola-sysv3
+       exit 0 ;;
+    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+       echo m88k-tektronix-sysv3
+       exit 0 ;;
+    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+       echo m68k-tektronix-bsd
+       exit 0 ;;
+    *:IRIX*:*:*)
+       echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+       exit 0 ;;
+    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+       echo romp-ibm-aix      # uname -m gives an 8 hex-code CPU id
+       exit 0 ;;              # Note that: echo "'`uname -s`'" gives 'AIX '
+    i?86:AIX:*:*)
+       echo i386-ibm-aix
+       exit 0 ;;
+    *:AIX:2:3)
+       if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+               sed 's/^                //' << EOF >$dummy.c
+               #include <sys/systemcfg.h>
+
+               main()
+                       {
+                       if (!__power_pc())
+                               exit(1);
+                       puts("powerpc-ibm-aix3.2.5");
+                       exit(0);
+                       }
+EOF
+               $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm $dummy.c $dummy && exit 0
+               rm -f $dummy.c $dummy
+               echo rs6000-ibm-aix3.2.5
+       elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+               echo rs6000-ibm-aix3.2.4
+       else
+               echo rs6000-ibm-aix3.2
+       fi
+       exit 0 ;;
+    *:AIX:*:4)
+       IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'`
+       if /usr/sbin/lsattr -EHl ${IBM_CPU_ID} | grep POWER >/dev/null 2>&1; then
+               IBM_ARCH=rs6000
+       else
+               IBM_ARCH=powerpc
+       fi
+       if [ -x /usr/bin/oslevel ] ; then
+               IBM_REV=`/usr/bin/oslevel`
+       else
+               IBM_REV=4.${UNAME_RELEASE}
+       fi
+       echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+       exit 0 ;;
+    *:AIX:*:*)
+       echo rs6000-ibm-aix
+       exit 0 ;;
+    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+       echo romp-ibm-bsd4.4
+       exit 0 ;;
+    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
+       echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
+       exit 0 ;;                           # report: romp-ibm BSD 4.3
+    *:BOSX:*:*)
+       echo rs6000-bull-bosx
+       exit 0 ;;
+    DPX/2?00:B.O.S.:*:*)
+       echo m68k-bull-sysv3
+       exit 0 ;;
+    9000/[34]??:4.3bsd:1.*:*)
+       echo m68k-hp-bsd
+       exit 0 ;;
+    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+       echo m68k-hp-bsd4.4
+       exit 0 ;;
+    9000/[34678]??:HP-UX:*:*)
+       case "${UNAME_MACHINE}" in
+           9000/31? )            HP_ARCH=m68000 ;;
+           9000/[34]?? )         HP_ARCH=m68k ;;
+           9000/[678][0-9][0-9])
+              sed 's/^              //' << EOF >$dummy.c
+
+              #define _HPUX_SOURCE
+              #include <stdlib.h>
+              #include <unistd.h>
+
+              int main ()
+              {
+              #if defined(_SC_KERNEL_BITS)
+                  long bits = sysconf(_SC_KERNEL_BITS);
+              #endif
+                  long cpu  = sysconf (_SC_CPU_VERSION);
+
+                  switch (cpu)
+               {
+               case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+               case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+               case CPU_PA_RISC2_0:
+              #if defined(_SC_KERNEL_BITS)
+                   switch (bits)
+                       {
+                       case 64: puts ("hppa2.0w"); break;
+                       case 32: puts ("hppa2.0n"); break;
+                       default: puts ("hppa2.0"); break;
+                       } break;
+              #else  /* !defined(_SC_KERNEL_BITS) */
+                   puts ("hppa2.0"); break;
+              #endif
+               default: puts ("hppa1.0"); break;
+               }
+                  exit (0);
+              }
+EOF
+       (CCOPTS= $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null ) && HP_ARCH=`./$dummy`
+       rm -f $dummy.c $dummy
+       esac
+       HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+       echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+       exit 0 ;;
+    3050*:HI-UX:*:*)
+       sed 's/^        //' << EOF >$dummy.c
+       #include <unistd.h>
+       int
+       main ()
+       {
+         long cpu = sysconf (_SC_CPU_VERSION);
+         /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+            true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
+            results, however.  */
+         if (CPU_IS_PA_RISC (cpu))
+           {
+             switch (cpu)
+               {
+                 case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+                 case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+                 case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+                 default: puts ("hppa-hitachi-hiuxwe2"); break;
+               }
+           }
+         else if (CPU_IS_HP_MC68K (cpu))
+           puts ("m68k-hitachi-hiuxwe2");
+         else puts ("unknown-hitachi-hiuxwe2");
+         exit (0);
+       }
+EOF
+       $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm $dummy.c $dummy && exit 0
+       rm -f $dummy.c $dummy
+       echo unknown-hitachi-hiuxwe2
+       exit 0 ;;
+    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+       echo hppa1.1-hp-bsd
+       exit 0 ;;
+    9000/8??:4.3bsd:*:*)
+       echo hppa1.0-hp-bsd
+       exit 0 ;;
+    *9??*:MPE/iX:*:*)
+       echo hppa1.0-hp-mpeix
+       exit 0 ;;
+    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+       echo hppa1.1-hp-osf
+       exit 0 ;;
+    hp8??:OSF1:*:*)
+       echo hppa1.0-hp-osf
+       exit 0 ;;
+    i?86:OSF1:*:*)
+       if [ -x /usr/sbin/sysversion ] ; then
+           echo ${UNAME_MACHINE}-unknown-osf1mk
+       else
+           echo ${UNAME_MACHINE}-unknown-osf1
+       fi
+       exit 0 ;;
+    parisc*:Lites*:*:*)
+       echo hppa1.1-hp-lites
+       exit 0 ;;
+    hppa*:OpenBSD:*:*)
+       echo hppa-unknown-openbsd
+       exit 0 ;;
+    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+       echo c1-convex-bsd
+        exit 0 ;;
+    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+       if getsysinfo -f scalar_acc
+       then echo c32-convex-bsd
+       else echo c2-convex-bsd
+       fi
+        exit 0 ;;
+    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+       echo c34-convex-bsd
+        exit 0 ;;
+    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+       echo c38-convex-bsd
+        exit 0 ;;
+    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+       echo c4-convex-bsd
+        exit 0 ;;
+    CRAY*X-MP:*:*:*)
+       echo xmp-cray-unicos
+        exit 0 ;;
+    CRAY*Y-MP:*:*:*)
+       echo ymp-cray-unicos${UNAME_RELEASE}
+       exit 0 ;;
+    CRAY*[A-Z]90:*:*:*)
+       echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+       | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+             -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
+       exit 0 ;;
+    CRAY*TS:*:*:*)
+       echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit 0 ;;
+    CRAY*T3E:*:*:*)
+       echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit 0 ;;
+    CRAY*SV1:*:*:*)
+       echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit 0 ;;
+    CRAY-2:*:*:*)
+       echo cray2-cray-unicos
+        exit 0 ;;
+    F300:UNIX_System_V:*:*)
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+        echo "f300-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+        exit 0 ;;
+    F301:UNIX_System_V:*:*)
+       echo f301-fujitsu-uxpv`echo $UNAME_RELEASE | sed 's/ .*//'`
+       exit 0 ;;
+    hp300:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    i?86:BSD/386:*:* | i?86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+       echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+       exit 0 ;;
+    sparc*:BSD/OS:*:*)
+       echo sparc-unknown-bsdi${UNAME_RELEASE}
+       exit 0 ;;
+    *:BSD/OS:*:*)
+       echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+       exit 0 ;;
+    *:FreeBSD:*:*)
+       echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+       exit 0 ;;
+    *:OpenBSD:*:*)
+       echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+       exit 0 ;;
+    i*:CYGWIN*:*)
+       echo ${UNAME_MACHINE}-pc-cygwin
+       exit 0 ;;
+    i*:MINGW*:*)
+       echo ${UNAME_MACHINE}-pc-mingw32
+       exit 0 ;;
+    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+       # How do we know it's Interix rather than the generic POSIX subsystem?
+       # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+       # UNAME_MACHINE based on the output of uname instead of i386?
+       echo i386-pc-interix
+       exit 0 ;;
+    i*:UWIN*:*)
+       echo ${UNAME_MACHINE}-pc-uwin
+       exit 0 ;;
+    p*:CYGWIN*:*)
+       echo powerpcle-unknown-cygwin
+       exit 0 ;;
+    prep*:SunOS:5.*:*)
+       echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    *:GNU:*:*)
+       echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+       exit 0 ;;
+    *:Linux:*:*)
+
+       # The BFD linker knows what the default object file format is, so
+       # first see if it will tell us. cd to the root directory to prevent
+       # problems with other programs or directories called `ld' in the path.
+       ld_help_string=`cd /; ld --help 2>&1`
+       ld_supported_emulations=`echo $ld_help_string \
+                        | sed -ne '/supported emulations:/!d
+                                   s/[         ][      ]*/ /g
+                                   s/.*supported emulations: *//
+                                   s/ .*//
+                                   p'`
+        case "$ld_supported_emulations" in
+         *ia64)
+               echo "${UNAME_MACHINE}-unknown-linux"
+               exit 0
+               ;;
+         i?86linux)
+               echo "${UNAME_MACHINE}-pc-linux-gnuaout"
+               exit 0
+               ;;
+         elf_i?86)
+               echo "${UNAME_MACHINE}-pc-linux"
+               exit 0
+               ;;
+         i?86coff)
+               echo "${UNAME_MACHINE}-pc-linux-gnucoff"
+               exit 0
+               ;;
+         sparclinux)
+               echo "${UNAME_MACHINE}-unknown-linux-gnuaout"
+               exit 0
+               ;;
+         armlinux)
+               echo "${UNAME_MACHINE}-unknown-linux-gnuaout"
+               exit 0
+               ;;
+         elf32arm*)
+               echo "${UNAME_MACHINE}-unknown-linux-gnuoldld"
+               exit 0
+               ;;
+         armelf_linux*)
+               echo "${UNAME_MACHINE}-unknown-linux-gnu"
+               exit 0
+               ;;
+         m68klinux)
+               echo "${UNAME_MACHINE}-unknown-linux-gnuaout"
+               exit 0
+               ;;
+         elf32ppc | elf32ppclinux)
+               # Determine Lib Version
+               cat >$dummy.c <<EOF
+#include <features.h>
+#if defined(__GLIBC__)
+extern char __libc_version[];
+extern char __libc_release[];
+#endif
+main(argc, argv)
+     int argc;
+     char *argv[];
+{
+#if defined(__GLIBC__)
+  printf("%s %s\n", __libc_version, __libc_release);
+#else
+  printf("unkown\n");
+#endif
+  return 0;
+}
+EOF
+               LIBC=""
+               $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null
+               if test "$?" = 0 ; then
+                       ./$dummy | grep 1\.99 > /dev/null
+                       if test "$?" = 0 ; then
+                               LIBC="libc1"
+                       fi
+               fi
+               rm -f $dummy.c $dummy
+               echo powerpc-unknown-linux-gnu${LIBC}
+               exit 0
+               ;;
+       esac
+
+       if test "${UNAME_MACHINE}" = "alpha" ; then
+               cat <<EOF >$dummy.s
+                       .data
+               \$Lformat:
+                       .byte 37,100,45,37,120,10,0     # "%d-%x\n"
+
+                       .text
+                       .globl main
+                       .align 4
+                       .ent main
+               main:
+                       .frame \$30,16,\$26,0
+                       ldgp \$29,0(\$27)
+                       .prologue 1
+                       .long 0x47e03d80 # implver \$0
+                       lda \$2,-1
+                       .long 0x47e20c21 # amask \$2,\$1
+                       lda \$16,\$Lformat
+                       mov \$0,\$17
+                       not \$1,\$18
+                       jsr \$26,printf
+                       ldgp \$29,0(\$26)
+                       mov 0,\$16
+                       jsr \$26,exit
+                       .end main
+EOF
+               LIBC=""
+               $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
+               if test "$?" = 0 ; then
+                       case `./$dummy` in
+                       0-0)
+                               UNAME_MACHINE="alpha"
+                               ;;
+                       1-0)
+                               UNAME_MACHINE="alphaev5"
+                               ;;
+                       1-1)
+                               UNAME_MACHINE="alphaev56"
+                               ;;
+                       1-101)
+                               UNAME_MACHINE="alphapca56"
+                               ;;
+                       2-303)
+                               UNAME_MACHINE="alphaev6"
+                               ;;
+                       2-307)
+                               UNAME_MACHINE="alphaev67"
+                               ;;
+                       esac
+
+                       objdump --private-headers $dummy | \
+                         grep ld.so.1 > /dev/null
+                       if test "$?" = 0 ; then
+                               LIBC="libc1"
+                       fi
+               fi
+               rm -f $dummy.s $dummy
+               echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} ; exit 0
+       elif test "${UNAME_MACHINE}" = "mips" ; then
+         cat >$dummy.c <<EOF
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+       int main (int argc, char *argv[]) {
+#else
+       int main (argc, argv) int argc; char *argv[]; {
+#endif
+#ifdef __MIPSEB__
+  printf ("%s-unknown-linux-gnu\n", argv[1]);
+#endif
+#ifdef __MIPSEL__
+  printf ("%sel-unknown-linux-gnu\n", argv[1]);
+#endif
+  return 0;
+}
+EOF
+         $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm $dummy.c $dummy && exit 0
+         rm -f $dummy.c $dummy
+       elif test "${UNAME_MACHINE}" = "s390"; then
+         echo s390-ibm-linux && exit 0
+       else
+         # Either a pre-BFD a.out linker (linux-gnuoldld)
+         # or one that does not give us useful --help.
+         # GCC wants to distinguish between linux-gnuoldld and linux-gnuaout.
+         # If ld does not provide *any* "supported emulations:"
+         # that means it is gnuoldld.
+         echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations:"
+         test $? != 0 && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0
+
+         case "${UNAME_MACHINE}" in
+         i?86)
+           VENDOR=pc;
+           ;;
+         *)
+           VENDOR=unknown;
+           ;;
+         esac
+         # Determine whether the default compiler is a.out or elf
+         cat >$dummy.c <<EOF
+#include <features.h>
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+       int main (int argc, char *argv[]) {
+#else
+       int main (argc, argv) int argc; char *argv[]; {
+#endif
+#ifdef __ELF__
+# ifdef __GLIBC__
+#  if __GLIBC__ >= 2
+    printf ("%s-${VENDOR}-linux-gnu\n", argv[1]);
+#  else
+    printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
+#  endif
+# else
+   printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
+# endif
+#else
+  printf ("%s-${VENDOR}-linux-gnuaout\n", argv[1]);
+#endif
+  return 0;
+}
+EOF
+         $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm $dummy.c $dummy && exit 0
+         rm -f $dummy.c $dummy
+       fi ;;
+# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.  earlier versions
+# are messed up and put the nodename in both sysname and nodename.
+    i?86:DYNIX/ptx:4*:*)
+       echo i386-sequent-sysv4
+       exit 0 ;;
+    i?86:UNIX_SV:4.2MP:2.*)
+        # Unixware is an offshoot of SVR4, but it has its own version
+        # number series starting with 2...
+        # I am not positive that other SVR4 systems won't match this,
+       # I just have to hope.  -- rms.
+        # Use sysv4.2uw... so that sysv4* matches it.
+       echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+       exit 0 ;;
+    i?86:*:4.*:* | i?86:SYSTEM_V:4.*:*)
+       UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+       if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+               echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+       else
+               echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+       fi
+       exit 0 ;;
+    i?86:*:5:7*)
+        # Fixed at (any) Pentium or better
+        UNAME_MACHINE=i586
+        if [ ${UNAME_SYSTEM} = "UnixWare" ] ; then
+           echo ${UNAME_MACHINE}-sco-sysv${UNAME_RELEASE}uw${UNAME_VERSION}
+       else
+           echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE}
+       fi
+       exit 0 ;;
+    i?86:*:3.2:*)
+       if test -f /usr/options/cb.name; then
+               UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+               echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+       elif /bin/uname -X 2>/dev/null >/dev/null ; then
+               UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
+               (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
+               (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
+                       && UNAME_MACHINE=i586
+               (/bin/uname -X|egrep '^Machine.*Pent ?II' >/dev/null) \
+                       && UNAME_MACHINE=i686
+               (/bin/uname -X|egrep '^Machine.*Pentium Pro' >/dev/null) \
+                       && UNAME_MACHINE=i686
+               echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+       else
+               echo ${UNAME_MACHINE}-pc-sysv32
+       fi
+       exit 0 ;;
+    i?86:*DOS:*:*)
+       echo ${UNAME_MACHINE}-pc-msdosdjgpp
+       exit 0 ;;
+    pc:*:*:*)
+       # Left here for compatibility:
+        # uname -m prints for DJGPP always 'pc', but it prints nothing about
+        # the processor, so we play safe by assuming i386.
+       echo i386-pc-msdosdjgpp
+        exit 0 ;;
+    Intel:Mach:3*:*)
+       echo i386-pc-mach3
+       exit 0 ;;
+    paragon:*:*:*)
+       echo i860-intel-osf1
+       exit 0 ;;
+    i860:*:4.*:*) # i860-SVR4
+       if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+         echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+       else # Add other i860-SVR4 vendors below as they are discovered.
+         echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
+       fi
+       exit 0 ;;
+    mini*:CTIX:SYS*5:*)
+       # "miniframe"
+       echo m68010-convergent-sysv
+       exit 0 ;;
+    M68*:*:R3V[567]*:*)
+       test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
+    3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0)
+       OS_REL=''
+       test -r /etc/.relid \
+       && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+       /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+         && echo i486-ncr-sysv4.3${OS_REL} && exit 0
+       /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+         && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
+    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+          && echo i486-ncr-sysv4 && exit 0 ;;
+    m68*:LynxOS:2.*:*)
+       echo m68k-unknown-lynxos${UNAME_RELEASE}
+       exit 0 ;;
+    mc68030:UNIX_System_V:4.*:*)
+       echo m68k-atari-sysv4
+       exit 0 ;;
+    i?86:LynxOS:2.*:* | i?86:LynxOS:3.[01]*:*)
+       echo i386-unknown-lynxos${UNAME_RELEASE}
+       exit 0 ;;
+    TSUNAMI:LynxOS:2.*:*)
+       echo sparc-unknown-lynxos${UNAME_RELEASE}
+       exit 0 ;;
+    rs6000:LynxOS:2.*:* | PowerPC:LynxOS:2.*:*)
+       echo rs6000-unknown-lynxos${UNAME_RELEASE}
+       exit 0 ;;
+    SM[BE]S:UNIX_SV:*:*)
+       echo mips-dde-sysv${UNAME_RELEASE}
+       exit 0 ;;
+    RM*:ReliantUNIX-*:*:*)
+       echo mips-sni-sysv4
+       exit 0 ;;
+    RM*:SINIX-*:*:*)
+       echo mips-sni-sysv4
+       exit 0 ;;
+    *:SINIX-*:*:*)
+       if uname -p 2>/dev/null >/dev/null ; then
+               UNAME_MACHINE=`(uname -p) 2>/dev/null`
+               echo ${UNAME_MACHINE}-sni-sysv4
+       else
+               echo ns32k-sni-sysv
+       fi
+       exit 0 ;;
+    PENTIUM:CPunix:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+                           # says <Richard.M.Bartel@ccMail.Census.GOV>
+        echo i586-unisys-sysv4
+        exit 0 ;;
+    *:UNIX_System_V:4*:FTX*)
+       # From Gerald Hewes <hewes@openmarket.com>.
+       # How about differentiating between stratus architectures? -djm
+       echo hppa1.1-stratus-sysv4
+       exit 0 ;;
+    *:*:*:FTX*)
+       # From seanf@swdc.stratus.com.
+       echo i860-stratus-sysv4
+       exit 0 ;;
+    mc68*:A/UX:*:*)
+       echo m68k-apple-aux${UNAME_RELEASE}
+       exit 0 ;;
+    news*:NEWS-OS:*:6*)
+       echo mips-sony-newsos6
+       exit 0 ;;
+    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+       if [ -d /usr/nec ]; then
+               echo mips-nec-sysv${UNAME_RELEASE}
+       else
+               echo mips-unknown-sysv${UNAME_RELEASE}
+       fi
+        exit 0 ;;
+    BeBox:BeOS:*:*)    # BeOS running on hardware made by Be, PPC only.
+       echo powerpc-be-beos
+       exit 0 ;;
+    BeMac:BeOS:*:*)    # BeOS running on Mac or Mac clone, PPC only.
+       echo powerpc-apple-beos
+       exit 0 ;;
+    BePC:BeOS:*:*)     # BeOS running on Intel PC compatible.
+       echo i586-pc-beos
+       exit 0 ;;
+    SX-4:SUPER-UX:*:*)
+       echo sx4-nec-superux${UNAME_RELEASE}
+       exit 0 ;;
+    SX-5:SUPER-UX:*:*)
+       echo sx5-nec-superux${UNAME_RELEASE}
+       exit 0 ;;
+    Power*:Rhapsody:*:*)
+       echo powerpc-apple-rhapsody${UNAME_RELEASE}
+       exit 0 ;;
+    *:Rhapsody:*:*)
+       echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+       exit 0 ;;
+    *:Darwin:*:*)
+       echo `uname -p`-apple-darwin${UNAME_RELEASE}
+       exit 0 ;;
+    *:procnto*:*:* | *:QNX:[0123456789]*:*)
+       if test "${UNAME_MACHINE}" = "x86pc"; then
+               UNAME_MACHINE=pc
+       fi
+       echo `uname -p`-${UNAME_MACHINE}-nto-qnx
+       exit 0 ;;
+    *:QNX:*:4*)
+       echo i386-pc-qnx
+       exit 0 ;;
+    NSR-W:NONSTOP_KERNEL:*:*)
+       echo nsr-tandem-nsk${UNAME_RELEASE}
+       exit 0 ;;
+    BS2000:POSIX*:*:*)
+       echo bs2000-siemens-sysv
+       exit 0 ;;
+    DS/*:UNIX_System_V:*:*)
+       echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+       exit 0 ;;
+esac
+
+#echo '(No uname command or uname output not recognized.)' 1>&2
+#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
+
+cat >$dummy.c <<EOF
+#ifdef _SEQUENT_
+# include <sys/types.h>
+# include <sys/utsname.h>
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
+     I don't know....  */
+  printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include <sys/param.h>
+  printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+          "4"
+#else
+         ""
+#endif
+         ); exit (0);
+#endif
+#endif
+
+#if defined (__arm) && defined (__acorn) && defined (__unix)
+  printf ("arm-acorn-riscix"); exit (0);
+#endif
+
+#if defined (hp300) && !defined (hpux)
+  printf ("m68k-hp-bsd\n"); exit (0);
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+  int version;
+  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+  if (version < 4)
+    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+  else
+    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
+  exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+  printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+  printf ("ns32k-encore-mach\n"); exit (0);
+#else
+  printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+  printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+  printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+  printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+    struct utsname un;
+
+    uname(&un);
+
+    if (strncmp(un.version, "V2", 2) == 0) {
+       printf ("i386-sequent-ptx2\n"); exit (0);
+    }
+    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+       printf ("i386-sequent-ptx1\n"); exit (0);
+    }
+    printf ("i386-sequent-ptx\n"); exit (0);
+
+#endif
+
+#if defined (vax)
+#if !defined (ultrix)
+  printf ("vax-dec-bsd\n"); exit (0);
+#else
+  printf ("vax-dec-ultrix\n"); exit (0);
+#endif
+#endif
+
+#if defined (alliant) && defined (i860)
+  printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+  exit (1);
+}
+EOF
+
+$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm $dummy.c $dummy && exit 0
+rm -f $dummy.c $dummy
+
+# Apollos put the system type in the environment.
+
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
+
+# Convex versions that predate uname can use getsysinfo(1)
+
+if [ -x /usr/convex/getsysinfo ]
+then
+    case `getsysinfo -f cpu_type` in
+    c1*)
+       echo c1-convex-bsd
+       exit 0 ;;
+    c2*)
+       if getsysinfo -f scalar_acc
+       then echo c32-convex-bsd
+       else echo c2-convex-bsd
+       fi
+       exit 0 ;;
+    c34*)
+       echo c34-convex-bsd
+       exit 0 ;;
+    c38*)
+       echo c38-convex-bsd
+       exit 0 ;;
+    c4*)
+       echo c4-convex-bsd
+       exit 0 ;;
+    esac
+fi
+
+#echo '(Unable to guess system type)' 1>&2
+
+exit 1
diff --git a/config.h.in b/config.h.in
new file mode 100644 (file)
index 0000000..c80a2e9
--- /dev/null
@@ -0,0 +1,53 @@
+/* config.h.in.  Generated automatically from configure.in by autoheader.  */
+
+/* Define if you have the strcoll function and it is properly defined.  */
+#undef HAVE_STRCOLL
+
+/* Define as __inline if that's what the C compiler calls it.  */
+#undef inline
+
+/* Define if you have the ANSI C header files.  */
+#undef STDC_HEADERS
+
+/* Define if you have the <stdarg.h> header file.  */
+#undef HAVE_STDARG_H
+
+#undef HAVE_SNPRINTF
+#undef HAVE_VSNPRINTF
+
+/* Define if you have the resizeterm function.  */
+#undef HAVE_RESIZETERM
+
+/* Define if you have the setlocale function.  */
+#undef HAVE_SETLOCALE
+
+/* Define if you have the <linux/termios.h> header file.  */
+#undef HAVE_LINUX_TERMIOS_H
+
+/* Define if you have the <locale.h> header file.  */
+#undef HAVE_LOCALE_H
+
+/* Define if you have the <ncurses.h> header file.  */
+#undef HAVE_NCURSES_H
+
+/* Define if you have the <string.h> header file.  */
+#undef HAVE_STRING_H
+
+/* Define if you have the <sys/ioctl.h> header file.  */
+#undef HAVE_SYS_IOCTL_H
+
+/* Define if you have the <termios.h> header file.  */
+#undef HAVE_TERMIOS_H
+
+/* Define if you have the <unistd.h> header file.  */
+#undef HAVE_UNISTD_H
+
+/* Name of package */
+#undef PACKAGE
+
+/* Version number of package */
+#undef VERSION
+
+/* Define if compiler has function prototypes */
+#undef PROTOTYPES
+
diff --git a/config.sub b/config.sub
new file mode 100644 (file)
index 0000000..c8e7785
--- /dev/null
@@ -0,0 +1,1268 @@
+#! /bin/sh
+# Configuration validation subroutine script, version 1.1.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
+#   Free Software Foundation, Inc.
+#
+# This file is (in principle) common to ALL GNU software.
+# The presence of a machine in this file suggests that SOME GNU software
+# can handle that machine.  It does not imply ALL GNU software can.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Written by Per Bothner <bothner@cygnus.com>.
+# Please send patches to <config-patches@gnu.org>.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#      CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#      CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+if [ x$1 = x ]
+then
+       echo Configuration name missing. 1>&2
+       echo "Usage: $0 CPU-MFR-OPSYS" 1>&2
+       echo "or     $0 ALIAS" 1>&2
+       echo where ALIAS is a recognized configuration type. 1>&2
+       exit 1
+fi
+
+# First pass through any local machine types.
+case $1 in
+       *local*)
+               echo $1
+               exit 0
+               ;;
+       *)
+       ;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+       -sun*os*)
+               # Prevent following clause from handling this invalid input.
+               ;;
+       -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+       -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+       -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+       -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+       -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+       -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+       -apple)
+               os=
+               basic_machine=$1
+               ;;
+       -sim | -cisco | -oki | -wec | -winbond)
+               os=
+               basic_machine=$1
+               ;;
+       -scout)
+               ;;
+       -wrs)
+               os=-vxworks
+               basic_machine=$1
+               ;;
+       -hiux*)
+               os=-hiuxwe2
+               ;;
+       -sco5)
+               os=-sco3.2v5
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco4)
+               os=-sco3.2v4
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco3.2.[4-9]*)
+               os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco3.2v[4-9]*)
+               # Don't forget version if it is 3.2v4 or newer.
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco*)
+               os=-sco3.2v2
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -udk*)
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -isc)
+               os=-isc2.2
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -clix*)
+               basic_machine=clipper-intergraph
+               ;;
+       -isc*)
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -lynx*)
+               os=-lynxos
+               ;;
+       -ptx*)
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+               ;;
+       -windowsnt*)
+               os=`echo $os | sed -e 's/windowsnt/winnt/'`
+               ;;
+       -psos*)
+               os=-psos
+               ;;
+       -mint | -mint[0-9]*)
+               basic_machine=m68k-atari
+               os=-mint
+               ;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+       # Recognize the basic CPU types without company name.
+       # Some are omitted here because they have special meanings below.
+       tahoe | i860 | ia64 | m32r | m68k | m68000 | m88k | ns32k | arc | arm \
+               | arme[lb] | pyramid | mn10200 | mn10300 | tron | a29k \
+               | 580 | i960 | h8300 \
+               | x86 | ppcbe | mipsbe | mipsle | shbe | shle | armbe | armle \
+               | hppa | hppa1.0 | hppa1.1 | hppa2.0 | hppa2.0w | hppa2.0n \
+               | hppa64 \
+               | alpha | alphaev[4-8] | alphaev56 | alphapca5[67] \
+               | alphaev6[78] \
+               | we32k | ns16k | clipper | i370 | sh | powerpc | powerpcle \
+               | 1750a | dsp16xx | pdp11 | mips16 | mips64 | mipsel | mips64el \
+               | mips64orion | mips64orionel | mipstx39 | mipstx39el \
+               | mips64vr4300 | mips64vr4300el | mips64vr4100 | mips64vr4100el \
+               | mips64vr5000 | miprs64vr5000el | mcore \
+               | sparc | sparclet | sparclite | sparc64 | sparcv9 | v850 | c4x \
+               | thumb | d10v | fr30 | avr)
+               basic_machine=$basic_machine-unknown
+               ;;
+       m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | z8k | v70 | h8500 | w65 | pj | pjl)
+               ;;
+
+       # We use `pc' rather than `unknown'
+       # because (1) that's what they normally are, and
+       # (2) the word "unknown" tends to confuse beginning users.
+       i[34567]86)
+         basic_machine=$basic_machine-pc
+         ;;
+       # Object if more than one company name word.
+       *-*-*)
+               echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+               exit 1
+               ;;
+       # Recognize the basic CPU types with company name.
+       # FIXME: clean up the formatting here.
+       vax-* | tahoe-* | i[34567]86-* | i860-* | ia64-* | m32r-* | m68k-* | m68000-* \
+             | m88k-* | sparc-* | ns32k-* | fx80-* | arc-* | arm-* | c[123]* \
+             | mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* \
+             | power-* | none-* | 580-* | cray2-* | h8300-* | h8500-* | i960-* \
+             | xmp-* | ymp-* \
+             | x86-* | ppcbe-* | mipsbe-* | mipsle-* | shbe-* | shle-* | armbe-* | armle-* \
+             | hppa-* | hppa1.0-* | hppa1.1-* | hppa2.0-* | hppa2.0w-* \
+             | hppa2.0n-* | hppa64-* \
+             | alpha-* | alphaev[4-8]-* | alphaev56-* | alphapca5[67]-* \
+             | alphaev6[78]-* \
+             | we32k-* | cydra-* | ns16k-* | pn-* | np1-* | xps100-* \
+             | clipper-* | orion-* \
+             | sparclite-* | pdp11-* | sh-* | powerpc-* | powerpcle-* \
+             | sparc64-* | sparcv9-* | sparc86x-* | mips16-* | mips64-* | mipsel-* \
+             | mips64el-* | mips64orion-* | mips64orionel-* \
+             | mips64vr4100-* | mips64vr4100el-* | mips64vr4300-* | mips64vr4300el-* \
+             | mipstx39-* | mipstx39el-* | mcore-* \
+             | f301-* | armv*-* | s390-* | sv1-* | t3e-* \
+             | m88110-* | m680[01234]0-* | m683?2-* | m68360-* | z8k-* | d10v-* \
+             | thumb-* | v850-* | d30v-* | tic30-* | c30-* | fr30-* \
+             | bs2000-*)
+               ;;
+       # Recognize the various machine names and aliases which stand
+       # for a CPU type and a company and sometimes even an OS.
+       386bsd)
+               basic_machine=i386-unknown
+               os=-bsd
+               ;;
+       3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+               basic_machine=m68000-att
+               ;;
+       3b*)
+               basic_machine=we32k-att
+               ;;
+       a29khif)
+               basic_machine=a29k-amd
+               os=-udi
+               ;;
+       adobe68k)
+               basic_machine=m68010-adobe
+               os=-scout
+               ;;
+       alliant | fx80)
+               basic_machine=fx80-alliant
+               ;;
+       altos | altos3068)
+               basic_machine=m68k-altos
+               ;;
+       am29k)
+               basic_machine=a29k-none
+               os=-bsd
+               ;;
+       amdahl)
+               basic_machine=580-amdahl
+               os=-sysv
+               ;;
+       amiga | amiga-*)
+               basic_machine=m68k-cbm
+               ;;
+       amigaos | amigados)
+               basic_machine=m68k-cbm
+               os=-amigaos
+               ;;
+       amigaunix | amix)
+               basic_machine=m68k-cbm
+               os=-sysv4
+               ;;
+       apollo68)
+               basic_machine=m68k-apollo
+               os=-sysv
+               ;;
+       apollo68bsd)
+               basic_machine=m68k-apollo
+               os=-bsd
+               ;;
+       aux)
+               basic_machine=m68k-apple
+               os=-aux
+               ;;
+       balance)
+               basic_machine=ns32k-sequent
+               os=-dynix
+               ;;
+       convex-c1)
+               basic_machine=c1-convex
+               os=-bsd
+               ;;
+       convex-c2)
+               basic_machine=c2-convex
+               os=-bsd
+               ;;
+       convex-c32)
+               basic_machine=c32-convex
+               os=-bsd
+               ;;
+       convex-c34)
+               basic_machine=c34-convex
+               os=-bsd
+               ;;
+       convex-c38)
+               basic_machine=c38-convex
+               os=-bsd
+               ;;
+       cray | ymp)
+               basic_machine=ymp-cray
+               os=-unicos
+               ;;
+       cray2)
+               basic_machine=cray2-cray
+               os=-unicos
+               ;;
+       [ctj]90-cray)
+               basic_machine=c90-cray
+               os=-unicos
+               ;;
+       crds | unos)
+               basic_machine=m68k-crds
+               ;;
+       da30 | da30-*)
+               basic_machine=m68k-da30
+               ;;
+       decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+               basic_machine=mips-dec
+               ;;
+       delta | 3300 | motorola-3300 | motorola-delta \
+             | 3300-motorola | delta-motorola)
+               basic_machine=m68k-motorola
+               ;;
+       delta88)
+               basic_machine=m88k-motorola
+               os=-sysv3
+               ;;
+       dpx20 | dpx20-*)
+               basic_machine=rs6000-bull
+               os=-bosx
+               ;;
+       dpx2* | dpx2*-bull)
+               basic_machine=m68k-bull
+               os=-sysv3
+               ;;
+       ebmon29k)
+               basic_machine=a29k-amd
+               os=-ebmon
+               ;;
+       elxsi)
+               basic_machine=elxsi-elxsi
+               os=-bsd
+               ;;
+       encore | umax | mmax)
+               basic_machine=ns32k-encore
+               ;;
+       es1800 | OSE68k | ose68k | ose | OSE)
+               basic_machine=m68k-ericsson
+               os=-ose
+               ;;
+       fx2800)
+               basic_machine=i860-alliant
+               ;;
+       genix)
+               basic_machine=ns32k-ns
+               ;;
+       gmicro)
+               basic_machine=tron-gmicro
+               os=-sysv
+               ;;
+       h3050r* | hiux*)
+               basic_machine=hppa1.1-hitachi
+               os=-hiuxwe2
+               ;;
+       h8300hms)
+               basic_machine=h8300-hitachi
+               os=-hms
+               ;;
+       h8300xray)
+               basic_machine=h8300-hitachi
+               os=-xray
+               ;;
+       h8500hms)
+               basic_machine=h8500-hitachi
+               os=-hms
+               ;;
+       harris)
+               basic_machine=m88k-harris
+               os=-sysv3
+               ;;
+       hp300-*)
+               basic_machine=m68k-hp
+               ;;
+       hp300bsd)
+               basic_machine=m68k-hp
+               os=-bsd
+               ;;
+       hp300hpux)
+               basic_machine=m68k-hp
+               os=-hpux
+               ;;
+       hp3k9[0-9][0-9] | hp9[0-9][0-9])
+               basic_machine=hppa1.0-hp
+               ;;
+       hp9k2[0-9][0-9] | hp9k31[0-9])
+               basic_machine=m68000-hp
+               ;;
+       hp9k3[2-9][0-9])
+               basic_machine=m68k-hp
+               ;;
+       hp9k6[0-9][0-9] | hp6[0-9][0-9])
+               basic_machine=hppa1.0-hp
+               ;;
+       hp9k7[0-79][0-9] | hp7[0-79][0-9])
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k78[0-9] | hp78[0-9])
+               # FIXME: really hppa2.0-hp
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+               # FIXME: really hppa2.0-hp
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k8[0-9][13679] | hp8[0-9][13679])
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k8[0-9][0-9] | hp8[0-9][0-9])
+               basic_machine=hppa1.0-hp
+               ;;
+       hppa-next)
+               os=-nextstep3
+               ;;
+       hppaosf)
+               basic_machine=hppa1.1-hp
+               os=-osf
+               ;;
+       hppro)
+               basic_machine=hppa1.1-hp
+               os=-proelf
+               ;;
+       i370-ibm* | ibm*)
+               basic_machine=i370-ibm
+               ;;
+# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
+       i[34567]86v32)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-sysv32
+               ;;
+       i[34567]86v4*)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-sysv4
+               ;;
+       i[34567]86v)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-sysv
+               ;;
+       i[34567]86sol2)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-solaris2
+               ;;
+       i386mach)
+               basic_machine=i386-mach
+               os=-mach
+               ;;
+       i386-vsta | vsta)
+               basic_machine=i386-unknown
+               os=-vsta
+               ;;
+       i386-go32 | go32)
+               basic_machine=i386-unknown
+               os=-go32
+               ;;
+       i386-mingw32 | mingw32)
+               basic_machine=i386-unknown
+               os=-mingw32
+               ;;
+       iris | iris4d)
+               basic_machine=mips-sgi
+               case $os in
+                   -irix*)
+                       ;;
+                   *)
+                       os=-irix4
+                       ;;
+               esac
+               ;;
+       isi68 | isi)
+               basic_machine=m68k-isi
+               os=-sysv
+               ;;
+       m88k-omron*)
+               basic_machine=m88k-omron
+               ;;
+       magnum | m3230)
+               basic_machine=mips-mips
+               os=-sysv
+               ;;
+       merlin)
+               basic_machine=ns32k-utek
+               os=-sysv
+               ;;
+       miniframe)
+               basic_machine=m68000-convergent
+               ;;
+       *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+               basic_machine=m68k-atari
+               os=-mint
+               ;;
+       mipsel*-linux*)
+               basic_machine=mipsel-unknown
+               os=-linux-gnu
+               ;;
+       mips*-linux*)
+               basic_machine=mips-unknown
+               os=-linux-gnu
+               ;;
+       mips3*-*)
+               basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+               ;;
+       mips3*)
+               basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+               ;;
+       mmix*)
+               basic_machine=mmix-knuth
+               os=-mmixware
+               ;;
+       monitor)
+               basic_machine=m68k-rom68k
+               os=-coff
+               ;;
+       msdos)
+               basic_machine=i386-unknown
+               os=-msdos
+               ;;
+       mvs)
+               basic_machine=i370-ibm
+               os=-mvs
+               ;;
+       ncr3000)
+               basic_machine=i486-ncr
+               os=-sysv4
+               ;;
+       netbsd386)
+               basic_machine=i386-unknown
+               os=-netbsd
+               ;;
+       netwinder)
+               basic_machine=armv4l-rebel
+               os=-linux
+               ;;
+       news | news700 | news800 | news900)
+               basic_machine=m68k-sony
+               os=-newsos
+               ;;
+       news1000)
+               basic_machine=m68030-sony
+               os=-newsos
+               ;;
+       news-3600 | risc-news)
+               basic_machine=mips-sony
+               os=-newsos
+               ;;
+       necv70)
+               basic_machine=v70-nec
+               os=-sysv
+               ;;
+       next | m*-next )
+               basic_machine=m68k-next
+               case $os in
+                   -nextstep* )
+                       ;;
+                   -ns2*)
+                     os=-nextstep2
+                       ;;
+                   *)
+                     os=-nextstep3
+                       ;;
+               esac
+               ;;
+       nh3000)
+               basic_machine=m68k-harris
+               os=-cxux
+               ;;
+       nh[45]000)
+               basic_machine=m88k-harris
+               os=-cxux
+               ;;
+       nindy960)
+               basic_machine=i960-intel
+               os=-nindy
+               ;;
+       mon960)
+               basic_machine=i960-intel
+               os=-mon960
+               ;;
+       np1)
+               basic_machine=np1-gould
+               ;;
+       nsr-tandem)
+               basic_machine=nsr-tandem
+               ;;
+       op50n-* | op60c-*)
+               basic_machine=hppa1.1-oki
+               os=-proelf
+               ;;
+       OSE68000 | ose68000)
+               basic_machine=m68000-ericsson
+               os=-ose
+               ;;
+       os68k)
+               basic_machine=m68k-none
+               os=-os68k
+               ;;
+       pa-hitachi)
+               basic_machine=hppa1.1-hitachi
+               os=-hiuxwe2
+               ;;
+       paragon)
+               basic_machine=i860-intel
+               os=-osf
+               ;;
+       pbd)
+               basic_machine=sparc-tti
+               ;;
+       pbb)
+               basic_machine=m68k-tti
+               ;;
+        pc532 | pc532-*)
+               basic_machine=ns32k-pc532
+               ;;
+       pentium | p5 | k5 | k6 | nexen)
+               basic_machine=i586-pc
+               ;;
+       pentiumpro | p6 | 6x86)
+               basic_machine=i686-pc
+               ;;
+       pentiumii | pentium2)
+               basic_machine=i786-pc
+               ;;
+       pentium-* | p5-* | k5-* | k6-* | nexen-*)
+               basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pentiumpro-* | p6-* | 6x86-*)
+               basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pentiumii-* | pentium2-*)
+               basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pn)
+               basic_machine=pn-gould
+               ;;
+       power)  basic_machine=rs6000-ibm
+               ;;
+       ppc)    basic_machine=powerpc-unknown
+               ;;
+       ppc-*)  basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       ppcle | powerpclittle | ppc-le | powerpc-little)
+               basic_machine=powerpcle-unknown
+               ;;
+       ppcle-* | powerpclittle-*)
+               basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       ps2)
+               basic_machine=i386-ibm
+               ;;
+       rom68k)
+               basic_machine=m68k-rom68k
+               os=-coff
+               ;;
+       rm[46]00)
+               basic_machine=mips-siemens
+               ;;
+       rtpc | rtpc-*)
+               basic_machine=romp-ibm
+               ;;
+       sa29200)
+               basic_machine=a29k-amd
+               os=-udi
+               ;;
+       sequent)
+               basic_machine=i386-sequent
+               ;;
+       sh)
+               basic_machine=sh-hitachi
+               os=-hms
+               ;;
+       sparclite-wrs)
+               basic_machine=sparclite-wrs
+               os=-vxworks
+               ;;
+       sps7)
+               basic_machine=m68k-bull
+               os=-sysv2
+               ;;
+       spur)
+               basic_machine=spur-unknown
+               ;;
+       st2000)
+               basic_machine=m68k-tandem
+               ;;
+       stratus)
+               basic_machine=i860-stratus
+               os=-sysv4
+               ;;
+       sun2)
+               basic_machine=m68000-sun
+               ;;
+       sun2os3)
+               basic_machine=m68000-sun
+               os=-sunos3
+               ;;
+       sun2os4)
+               basic_machine=m68000-sun
+               os=-sunos4
+               ;;
+       sun3os3)
+               basic_machine=m68k-sun
+               os=-sunos3
+               ;;
+       sun3os4)
+               basic_machine=m68k-sun
+               os=-sunos4
+               ;;
+       sun4os3)
+               basic_machine=sparc-sun
+               os=-sunos3
+               ;;
+       sun4os4)
+               basic_machine=sparc-sun
+               os=-sunos4
+               ;;
+       sun4sol2)
+               basic_machine=sparc-sun
+               os=-solaris2
+               ;;
+       sun3 | sun3-*)
+               basic_machine=m68k-sun
+               ;;
+       sun4)
+               basic_machine=sparc-sun
+               ;;
+       sun386 | sun386i | roadrunner)
+               basic_machine=i386-sun
+               ;;
+       sv1)
+               basic_machine=sv1-cray
+               os=-unicos
+               ;;
+       symmetry)
+               basic_machine=i386-sequent
+               os=-dynix
+               ;;
+       t3e)
+               basic_machine=t3e-cray
+               os=-unicos
+               ;;
+       tx39)
+               basic_machine=mipstx39-unknown
+               ;;
+       tx39el)
+               basic_machine=mipstx39el-unknown
+               ;;
+       tower | tower-32)
+               basic_machine=m68k-ncr
+               ;;
+       udi29k)
+               basic_machine=a29k-amd
+               os=-udi
+               ;;
+       ultra3)
+               basic_machine=a29k-nyu
+               os=-sym1
+               ;;
+       v810 | necv810)
+               basic_machine=v810-nec
+               os=-none
+               ;;
+       vaxv)
+               basic_machine=vax-dec
+               os=-sysv
+               ;;
+       vms)
+               basic_machine=vax-dec
+               os=-vms
+               ;;
+       vpp*|vx|vx-*)
+               basic_machine=f301-fujitsu
+               ;;
+       vxworks960)
+               basic_machine=i960-wrs
+               os=-vxworks
+               ;;
+       vxworks68)
+               basic_machine=m68k-wrs
+               os=-vxworks
+               ;;
+       vxworks29k)
+               basic_machine=a29k-wrs
+               os=-vxworks
+               ;;
+       w65*)
+               basic_machine=w65-wdc
+               os=-none
+               ;;
+       w89k-*)
+               basic_machine=hppa1.1-winbond
+               os=-proelf
+               ;;
+       xmp)
+               basic_machine=xmp-cray
+               os=-unicos
+               ;;
+        xps | xps100)
+               basic_machine=xps100-honeywell
+               ;;
+       z8k-*-coff)
+               basic_machine=z8k-unknown
+               os=-sim
+               ;;
+       none)
+               basic_machine=none-none
+               os=-none
+               ;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+       w89k)
+               basic_machine=hppa1.1-winbond
+               ;;
+       op50n)
+               basic_machine=hppa1.1-oki
+               ;;
+       op60c)
+               basic_machine=hppa1.1-oki
+               ;;
+       mips)
+               if [ x$os = x-linux-gnu ]; then
+                       basic_machine=mips-unknown
+               else
+                       basic_machine=mips-mips
+               fi
+               ;;
+       romp)
+               basic_machine=romp-ibm
+               ;;
+       rs6000)
+               basic_machine=rs6000-ibm
+               ;;
+       vax)
+               basic_machine=vax-dec
+               ;;
+       pdp11)
+               basic_machine=pdp11-dec
+               ;;
+       we32k)
+               basic_machine=we32k-att
+               ;;
+       sparc | sparcv9)
+               basic_machine=sparc-sun
+               ;;
+        cydra)
+               basic_machine=cydra-cydrome
+               ;;
+       orion)
+               basic_machine=orion-highlevel
+               ;;
+       orion105)
+               basic_machine=clipper-highlevel
+               ;;
+       mac | mpw | mac-mpw)
+               basic_machine=m68k-apple
+               ;;
+       pmac | pmac-mpw)
+               basic_machine=powerpc-apple
+               ;;
+       c4x*)
+               basic_machine=c4x-none
+               os=-coff
+               ;;
+       *)
+               echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+               exit 1
+               ;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+       *-digital*)
+               basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+               ;;
+       *-commodore*)
+               basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+               ;;
+       *)
+               ;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+        # First match some system type aliases
+        # that might get confused with valid system types.
+       # -solaris* is a basic system type, with this one exception.
+       -solaris1 | -solaris1.*)
+               os=`echo $os | sed -e 's|solaris1|sunos4|'`
+               ;;
+       -solaris)
+               os=-solaris2
+               ;;
+       -svr4*)
+               os=-sysv4
+               ;;
+       -unixware*)
+               os=-sysv4.2uw
+               ;;
+       -gnu/linux*)
+               os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+               ;;
+       # First accept the basic system types.
+       # The portable systems comes first.
+       # Each alternative MUST END IN A *, to match a version number.
+       # -sysv* is not here because it comes later, after sysvr4.
+       -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+             | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+             | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
+             | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+             | -aos* \
+             | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+             | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+             | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
+             | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+             | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+             | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+             | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+             | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \
+             | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \
+             | -openstep* | -oskit*)
+       # Remember, each alternative MUST END IN *, to match a version number.
+               ;;
+       -qnx*)
+               case $basic_machine in
+                   x86-* | i[34567]86-*)
+                       ;;
+                   *)
+                       os=-nto$os
+                       ;;
+               esac
+               ;;
+       -nto*)
+               os=-nto-qnx
+               ;;
+       -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+             | -windows* | -osx | -abug | -netware* | -os9* | -beos* \
+             | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+               ;;
+       -mac*)
+               os=`echo $os | sed -e 's|mac|macos|'`
+               ;;
+       -linux*)
+               os=`echo $os | sed -e 's|linux|linux-gnu|'`
+               ;;
+       -sunos5*)
+               os=`echo $os | sed -e 's|sunos5|solaris2|'`
+               ;;
+       -sunos6*)
+               os=`echo $os | sed -e 's|sunos6|solaris3|'`
+               ;;
+       -opened*)
+               os=-openedition
+               ;;
+       -wince*)
+               os=-wince
+               ;;
+       -osfrose*)
+               os=-osfrose
+               ;;
+       -osf*)
+               os=-osf
+               ;;
+       -utek*)
+               os=-bsd
+               ;;
+       -dynix*)
+               os=-bsd
+               ;;
+       -acis*)
+               os=-aos
+               ;;
+       -386bsd)
+               os=-bsd
+               ;;
+       -ctix* | -uts*)
+               os=-sysv
+               ;;
+       -ns2 )
+               os=-nextstep2
+               ;;
+       -nsk)
+               os=-nsk
+               ;;
+       # Preserve the version number of sinix5.
+       -sinix5.*)
+               os=`echo $os | sed -e 's|sinix|sysv|'`
+               ;;
+       -sinix*)
+               os=-sysv4
+               ;;
+       -triton*)
+               os=-sysv3
+               ;;
+       -oss*)
+               os=-sysv3
+               ;;
+       -svr4)
+               os=-sysv4
+               ;;
+       -svr3)
+               os=-sysv3
+               ;;
+       -sysvr4)
+               os=-sysv4
+               ;;
+       # This must come after -sysvr4.
+       -sysv*)
+               ;;
+       -ose*)
+               os=-ose
+               ;;
+       -es1800*)
+               os=-ose
+               ;;
+       -xenix)
+               os=-xenix
+               ;;
+        -*mint | -*MiNT)
+               os=-mint
+               ;;
+       -none)
+               ;;
+       *)
+               # Get rid of the `-' at the beginning of $os.
+               os=`echo $os | sed 's/[^-]*-//'`
+               echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+               exit 1
+               ;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+       *-acorn)
+               os=-riscix1.2
+               ;;
+       arm*-rebel)
+               os=-linux
+               ;;
+       arm*-semi)
+               os=-aout
+               ;;
+        pdp11-*)
+               os=-none
+               ;;
+       *-dec | vax-*)
+               os=-ultrix4.2
+               ;;
+       m68*-apollo)
+               os=-domain
+               ;;
+       i386-sun)
+               os=-sunos4.0.2
+               ;;
+       m68000-sun)
+               os=-sunos3
+               # This also exists in the configure program, but was not the
+               # default.
+               # os=-sunos4
+               ;;
+       m68*-cisco)
+               os=-aout
+               ;;
+       mips*-cisco)
+               os=-elf
+               ;;
+       mips*-*)
+               os=-elf
+               ;;
+       *-tti)  # must be before sparc entry or we get the wrong os.
+               os=-sysv3
+               ;;
+       sparc-* | *-sun)
+               os=-sunos4.1.1
+               ;;
+       *-be)
+               os=-beos
+               ;;
+       *-ibm)
+               os=-aix
+               ;;
+       *-wec)
+               os=-proelf
+               ;;
+       *-winbond)
+               os=-proelf
+               ;;
+       *-oki)
+               os=-proelf
+               ;;
+       *-hp)
+               os=-hpux
+               ;;
+       *-hitachi)
+               os=-hiux
+               ;;
+       i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+               os=-sysv
+               ;;
+       *-cbm)
+               os=-amigaos
+               ;;
+       *-dg)
+               os=-dgux
+               ;;
+       *-dolphin)
+               os=-sysv3
+               ;;
+       m68k-ccur)
+               os=-rtu
+               ;;
+       m88k-omron*)
+               os=-luna
+               ;;
+       *-next )
+               os=-nextstep
+               ;;
+       *-sequent)
+               os=-ptx
+               ;;
+       *-crds)
+               os=-unos
+               ;;
+       *-ns)
+               os=-genix
+               ;;
+       i370-*)
+               os=-mvs
+               ;;
+       *-next)
+               os=-nextstep3
+               ;;
+        *-gould)
+               os=-sysv
+               ;;
+        *-highlevel)
+               os=-bsd
+               ;;
+       *-encore)
+               os=-bsd
+               ;;
+        *-sgi)
+               os=-irix
+               ;;
+        *-siemens)
+               os=-sysv4
+               ;;
+       *-masscomp)
+               os=-rtu
+               ;;
+       f301-fujitsu)
+               os=-uxpv
+               ;;
+       *-rom68k)
+               os=-coff
+               ;;
+       *-*bug)
+               os=-coff
+               ;;
+       *-apple)
+               os=-macos
+               ;;
+       *-atari*)
+               os=-mint
+               ;;
+       *)
+               os=-none
+               ;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+       *-unknown)
+               case $os in
+                       -riscix*)
+                               vendor=acorn
+                               ;;
+                       -sunos*)
+                               vendor=sun
+                               ;;
+                       -aix*)
+                               vendor=ibm
+                               ;;
+                       -beos*)
+                               vendor=be
+                               ;;
+                       -hpux*)
+                               vendor=hp
+                               ;;
+                       -mpeix*)
+                               vendor=hp
+                               ;;
+                       -hiux*)
+                               vendor=hitachi
+                               ;;
+                       -unos*)
+                               vendor=crds
+                               ;;
+                       -dgux*)
+                               vendor=dg
+                               ;;
+                       -luna*)
+                               vendor=omron
+                               ;;
+                       -genix*)
+                               vendor=ns
+                               ;;
+                       -mvs* | -opened*)
+                               vendor=ibm
+                               ;;
+                       -ptx*)
+                               vendor=sequent
+                               ;;
+                       -vxsim* | -vxworks*)
+                               vendor=wrs
+                               ;;
+                       -aux*)
+                               vendor=apple
+                               ;;
+                       -hms*)
+                               vendor=hitachi
+                               ;;
+                       -mpw* | -macos*)
+                               vendor=apple
+                               ;;
+                       -*mint | -*MiNT)
+                               vendor=atari
+                               ;;
+               esac
+               basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+               ;;
+esac
+
+echo $basic_machine$os
diff --git a/configure b/configure
new file mode 100755 (executable)
index 0000000..88bcba1
--- /dev/null
+++ b/configure
@@ -0,0 +1,2854 @@
+#! /bin/sh
+
+# Guess values for system-dependent variables and create Makefiles.
+# Generated automatically using autoconf version 2.13 
+# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+
+# Defaults:
+ac_help=
+ac_default_prefix=/usr/local
+# Any additions from configure.in:
+ac_help="$ac_help
+  --with-curses=DIR       Where ncurses is installed "
+ac_help="$ac_help
+  --enable-debug          Enable debugging support "
+
+# Initialize some variables set by options.
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+build=NONE
+cache_file=./config.cache
+exec_prefix=NONE
+host=NONE
+no_create=
+nonopt=NONE
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+target=NONE
+verbose=
+x_includes=NONE
+x_libraries=NONE
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datadir='${prefix}/share'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+libdir='${exec_prefix}/lib'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+infodir='${prefix}/info'
+mandir='${prefix}/man'
+
+# Initialize some other variables.
+subdirs=
+MFLAGS= MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
+# Maximum number of lines to put in a shell here document.
+ac_max_here_lines=12
+
+ac_prev=
+for ac_option
+do
+
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval "$ac_prev=\$ac_option"
+    ac_prev=
+    continue
+  fi
+
+  case "$ac_option" in
+  -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+  *) ac_optarg= ;;
+  esac
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case "$ac_option" in
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir="$ac_optarg" ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build="$ac_optarg" ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file="$ac_optarg" ;;
+
+  -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+  | --da=*)
+    datadir="$ac_optarg" ;;
+
+  -disable-* | --disable-*)
+    ac_feature=`echo $ac_option|sed -e 's/-*disable-//'`
+    # Reject names that are not valid shell variable names.
+    if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then
+      { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
+    fi
+    ac_feature=`echo $ac_feature| sed 's/-/_/g'`
+    eval "enable_${ac_feature}=no" ;;
+
+  -enable-* | --enable-*)
+    ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'`
+    # Reject names that are not valid shell variable names.
+    if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then
+      { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
+    fi
+    ac_feature=`echo $ac_feature| sed 's/-/_/g'`
+    case "$ac_option" in
+      *=*) ;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "enable_${ac_feature}='$ac_optarg'" ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix="$ac_optarg" ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he)
+    # Omit some internal or obsolete options to make the list less imposing.
+    # This message is too long to be a string in the A/UX 3.1 sh.
+    cat << EOF
+Usage: configure [options] [host]
+Options: [defaults in brackets after descriptions]
+Configuration:
+  --cache-file=FILE       cache test results in FILE
+  --help                  print this message
+  --no-create             do not create output files
+  --quiet, --silent       do not print \`checking...' messages
+  --version               print the version of autoconf that created configure
+Directory and file names:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+                          [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+                          [same as prefix]
+  --bindir=DIR            user executables in DIR [EPREFIX/bin]
+  --sbindir=DIR           system admin executables in DIR [EPREFIX/sbin]
+  --libexecdir=DIR        program executables in DIR [EPREFIX/libexec]
+  --datadir=DIR           read-only architecture-independent data in DIR
+                          [PREFIX/share]
+  --sysconfdir=DIR        read-only single-machine data in DIR [PREFIX/etc]
+  --sharedstatedir=DIR    modifiable architecture-independent data in DIR
+                          [PREFIX/com]
+  --localstatedir=DIR     modifiable single-machine data in DIR [PREFIX/var]
+  --libdir=DIR            object code libraries in DIR [EPREFIX/lib]
+  --includedir=DIR        C header files in DIR [PREFIX/include]
+  --oldincludedir=DIR     C header files for non-gcc in DIR [/usr/include]
+  --infodir=DIR           info documentation in DIR [PREFIX/info]
+  --mandir=DIR            man documentation in DIR [PREFIX/man]
+  --srcdir=DIR            find the sources in DIR [configure dir or ..]
+  --program-prefix=PREFIX prepend PREFIX to installed program names
+  --program-suffix=SUFFIX append SUFFIX to installed program names
+  --program-transform-name=PROGRAM
+                          run sed PROGRAM on installed program names
+EOF
+    cat << EOF
+Host type:
+  --build=BUILD           configure for building on BUILD [BUILD=HOST]
+  --host=HOST             configure for HOST [guessed]
+  --target=TARGET         configure for TARGET [TARGET=HOST]
+Features and packages:
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --x-includes=DIR        X include files are in DIR
+  --x-libraries=DIR       X library files are in DIR
+EOF
+    if test -n "$ac_help"; then
+      echo "--enable and --with options recognized:$ac_help"
+    fi
+    exit 0 ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host="$ac_optarg" ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir="$ac_optarg" ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir="$ac_optarg" ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir="$ac_optarg" ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir="$ac_optarg" ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst \
+  | --locals | --local | --loca | --loc | --lo)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+  | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+    localstatedir="$ac_optarg" ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir="$ac_optarg" ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir="$ac_optarg" ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix="$ac_optarg" ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix="$ac_optarg" ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix="$ac_optarg" ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name="$ac_optarg" ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir="$ac_optarg" ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir="$ac_optarg" ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site="$ac_optarg" ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir="$ac_optarg" ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir="$ac_optarg" ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target="$ac_optarg" ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers)
+    echo "configure generated by autoconf version 2.13"
+    exit 0 ;;
+
+  -with-* | --with-*)
+    ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
+    # Reject names that are not valid shell variable names.
+    if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then
+      { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
+    fi
+    ac_package=`echo $ac_package| sed 's/-/_/g'`
+    case "$ac_option" in
+      *=*) ;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "with_${ac_package}='$ac_optarg'" ;;
+
+  -without-* | --without-*)
+    ac_package=`echo $ac_option|sed -e 's/-*without-//'`
+    # Reject names that are not valid shell variable names.
+    if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then
+      { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
+    fi
+    ac_package=`echo $ac_package| sed 's/-/_/g'`
+    eval "with_${ac_package}=no" ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes="$ac_optarg" ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries="$ac_optarg" ;;
+
+  -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; }
+    ;;
+
+  *)
+    if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then
+      echo "configure: warning: $ac_option: invalid host type" 1>&2
+    fi
+    if test "x$nonopt" != xNONE; then
+      { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; }
+    fi
+    nonopt="$ac_option"
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; }
+fi
+
+trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
+
+# File descriptor usage:
+# 0 standard input
+# 1 file creation
+# 2 errors and warnings
+# 3 some systems may open it to /dev/tty
+# 4 used on the Kubota Titan
+# 6 checking for... messages and results
+# 5 compiler messages saved in config.log
+if test "$silent" = yes; then
+  exec 6>/dev/null
+else
+  exec 6>&1
+fi
+exec 5>./config.log
+
+echo "\
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+" 1>&5
+
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Also quote any args containing shell metacharacters.
+ac_configure_args=
+for ac_arg
+do
+  case "$ac_arg" in
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c) ;;
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;;
+  *" "*|*"     "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*)
+  ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+  *) ac_configure_args="$ac_configure_args $ac_arg" ;;
+  esac
+done
+
+# NLS nuisances.
+# Only set these to C if already set.  These must not be set unconditionally
+# because not all systems understand e.g. LANG=C (notably SCO).
+# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
+# Non-C LC_CTYPE values break the ctype check.
+if test "${LANG+set}"   = set; then LANG=C;   export LANG;   fi
+if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
+if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
+if test "${LC_CTYPE+set}"    = set; then LC_CTYPE=C;    export LC_CTYPE;    fi
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -rf conftest* confdefs.h
+# AIX cpp loses on an empty file, so make sure it contains at least a newline.
+echo > confdefs.h
+
+# A filename unique to this package, relative to the directory that
+# configure is in, which we can look for to find out if srcdir is correct.
+ac_unique_file=abook.c
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then its parent.
+  ac_prog=$0
+  ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'`
+  test "x$ac_confdir" = "x$ac_prog" && ac_confdir=.
+  srcdir=$ac_confdir
+  if test ! -r $srcdir/$ac_unique_file; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r $srcdir/$ac_unique_file; then
+  if test "$ac_srcdir_defaulted" = yes; then
+    { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; }
+  else
+    { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; }
+  fi
+fi
+srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'`
+
+# Prefer explicitly selected file to automatically selected ones.
+if test -z "$CONFIG_SITE"; then
+  if test "x$prefix" != xNONE; then
+    CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
+  else
+    CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
+  fi
+fi
+for ac_site_file in $CONFIG_SITE; do
+  if test -r "$ac_site_file"; then
+    echo "loading site script $ac_site_file"
+    . "$ac_site_file"
+  fi
+done
+
+if test -r "$cache_file"; then
+  echo "loading cache $cache_file"
+  . $cache_file
+else
+  echo "creating cache $cache_file"
+  > $cache_file
+fi
+
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+ac_exeext=
+ac_objext=o
+if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
+  # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
+  if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
+    ac_n= ac_c='
+' ac_t='       '
+  else
+    ac_n=-n ac_c= ac_t=
+  fi
+else
+  ac_n= ac_c='\c' ac_t=
+fi
+
+
+ac_aux_dir=
+for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
+  if test -f $ac_dir/install-sh; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install-sh -c"
+    break
+  elif test -f $ac_dir/install.sh; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install.sh -c"
+    break
+  fi
+done
+if test -z "$ac_aux_dir"; then
+  { echo "configure: error: can not find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." 1>&2; exit 1; }
+fi
+ac_config_guess=$ac_aux_dir/config.guess
+ac_config_sub=$ac_aux_dir/config.sub
+ac_configure=$ac_aux_dir/configure # This should be Cygnus configure.
+
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# ./install, which can be erroneously created by make from ./install.sh.
+echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
+echo "configure:560: checking for a BSD compatible install" >&5
+if test -z "$INSTALL"; then
+if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+    IFS="${IFS=        }"; ac_save_IFS="$IFS"; IFS=":"
+  for ac_dir in $PATH; do
+    # Account for people who put trailing slashes in PATH elements.
+    case "$ac_dir/" in
+    /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
+    *)
+      # OSF1 and SCO ODT 3.0 have their own names for install.
+      # Don't use installbsd from OSF since it installs stuff as root
+      # by default.
+      for ac_prog in ginstall scoinst install; do
+        if test -f $ac_dir/$ac_prog; then
+         if test $ac_prog = install &&
+            grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
+           # AIX install.  It has an incompatible calling convention.
+           :
+         else
+           ac_cv_path_install="$ac_dir/$ac_prog -c"
+           break 2
+         fi
+       fi
+      done
+      ;;
+    esac
+  done
+  IFS="$ac_save_IFS"
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL="$ac_cv_path_install"
+  else
+    # As a last resort, use the slow shell script.  We don't cache a
+    # path for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the path is relative.
+    INSTALL="$ac_install_sh"
+  fi
+fi
+echo "$ac_t""$INSTALL" 1>&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+echo $ac_n "checking whether build environment is sane""... $ac_c" 1>&6
+echo "configure:613: checking whether build environment is sane" >&5
+# Just in case
+sleep 1
+echo timestamp > conftestfile
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
+   if test "$*" = "X"; then
+      # -L didn't work.
+      set X `ls -t $srcdir/configure conftestfile`
+   fi
+   if test "$*" != "X $srcdir/configure conftestfile" \
+      && test "$*" != "X conftestfile $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      { echo "configure: error: ls -t appears to fail.  Make sure there is not a broken
+alias in your environment" 1>&2; exit 1; }
+   fi
+
+   test "$2" = conftestfile
+   )
+then
+   # Ok.
+   :
+else
+   { echo "configure: error: newly created file is older than distributed files!
+Check your system clock" 1>&2; exit 1; }
+fi
+rm -f conftest*
+echo "$ac_t""yes" 1>&6
+if test "$program_transform_name" = s,x,x,; then
+  program_transform_name=
+else
+  # Double any \ or $.  echo might interpret backslashes.
+  cat <<\EOF_SED > conftestsed
+s,\\,\\\\,g; s,\$,$$,g
+EOF_SED
+  program_transform_name="`echo $program_transform_name|sed -f conftestsed`"
+  rm -f conftestsed
+fi
+test "$program_prefix" != NONE &&
+  program_transform_name="s,^,${program_prefix},; $program_transform_name"
+# Use a double $ so make ignores it.
+test "$program_suffix" != NONE &&
+  program_transform_name="s,\$\$,${program_suffix},; $program_transform_name"
+
+# sed with no file args requires a program.
+test "$program_transform_name" = "" && program_transform_name="s,x,x,"
+
+echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
+echo "configure:670: checking whether ${MAKE-make} sets \${MAKE}" >&5
+set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftestmake <<\EOF
+all:
+       @echo 'ac_maketemp="${MAKE}"'
+EOF
+# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+eval `${MAKE-make} -f conftestmake 2>/dev/null | grep temp=`
+if test -n "$ac_maketemp"; then
+  eval ac_cv_prog_make_${ac_make}_set=yes
+else
+  eval ac_cv_prog_make_${ac_make}_set=no
+fi
+rm -f conftestmake
+fi
+if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  SET_MAKE=
+else
+  echo "$ac_t""no" 1>&6
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+
+PACKAGE=abook
+
+VERSION=0.4.16
+
+if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
+  { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; }
+fi
+cat >> confdefs.h <<EOF
+#define PACKAGE "$PACKAGE"
+EOF
+
+cat >> confdefs.h <<EOF
+#define VERSION "$VERSION"
+EOF
+
+
+
+missing_dir=`cd $ac_aux_dir && pwd`
+echo $ac_n "checking for working aclocal""... $ac_c" 1>&6
+echo "configure:716: checking for working aclocal" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf.  Sigh.
+if (aclocal --version) < /dev/null > /dev/null 2>&1; then
+   ACLOCAL=aclocal
+   echo "$ac_t""found" 1>&6
+else
+   ACLOCAL="$missing_dir/missing aclocal"
+   echo "$ac_t""missing" 1>&6
+fi
+
+echo $ac_n "checking for working autoconf""... $ac_c" 1>&6
+echo "configure:729: checking for working autoconf" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf.  Sigh.
+if (autoconf --version) < /dev/null > /dev/null 2>&1; then
+   AUTOCONF=autoconf
+   echo "$ac_t""found" 1>&6
+else
+   AUTOCONF="$missing_dir/missing autoconf"
+   echo "$ac_t""missing" 1>&6
+fi
+
+echo $ac_n "checking for working automake""... $ac_c" 1>&6
+echo "configure:742: checking for working automake" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf.  Sigh.
+if (automake --version) < /dev/null > /dev/null 2>&1; then
+   AUTOMAKE=automake
+   echo "$ac_t""found" 1>&6
+else
+   AUTOMAKE="$missing_dir/missing automake"
+   echo "$ac_t""missing" 1>&6
+fi
+
+echo $ac_n "checking for working autoheader""... $ac_c" 1>&6
+echo "configure:755: checking for working autoheader" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf.  Sigh.
+if (autoheader --version) < /dev/null > /dev/null 2>&1; then
+   AUTOHEADER=autoheader
+   echo "$ac_t""found" 1>&6
+else
+   AUTOHEADER="$missing_dir/missing autoheader"
+   echo "$ac_t""missing" 1>&6
+fi
+
+echo $ac_n "checking for working makeinfo""... $ac_c" 1>&6
+echo "configure:768: checking for working makeinfo" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf.  Sigh.
+if (makeinfo --version) < /dev/null > /dev/null 2>&1; then
+   MAKEINFO=makeinfo
+   echo "$ac_t""found" 1>&6
+else
+   MAKEINFO="$missing_dir/missing makeinfo"
+   echo "$ac_t""missing" 1>&6
+fi
+
+
+
+
+
+
+
+# Make sure we can run config.sub.
+if ${CONFIG_SHELL-/bin/sh} $ac_config_sub sun4 >/dev/null 2>&1; then :
+else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; }
+fi
+
+echo $ac_n "checking host system type""... $ac_c" 1>&6
+echo "configure:792: checking host system type" >&5
+
+host_alias=$host
+case "$host_alias" in
+NONE)
+  case $nonopt in
+  NONE)
+    if host_alias=`${CONFIG_SHELL-/bin/sh} $ac_config_guess`; then :
+    else { echo "configure: error: can not guess host type; you must specify one" 1>&2; exit 1; }
+    fi ;;
+  *) host_alias=$nonopt ;;
+  esac ;;
+esac
+
+host=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $host_alias`
+host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+echo "$ac_t""$host" 1>&6
+
+
+# Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:816: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  IFS="${IFS=  }"; ac_save_ifs="$IFS"; IFS=":"
+  ac_dummy="$PATH"
+  for ac_dir in $ac_dummy; do
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$ac_word; then
+      ac_cv_prog_CC="gcc"
+      break
+    fi
+  done
+  IFS="$ac_save_ifs"
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+  echo "$ac_t""$CC" 1>&6
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:846: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  IFS="${IFS=  }"; ac_save_ifs="$IFS"; IFS=":"
+  ac_prog_rejected=no
+  ac_dummy="$PATH"
+  for ac_dir in $ac_dummy; do
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$ac_word; then
+      if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then
+        ac_prog_rejected=yes
+       continue
+      fi
+      ac_cv_prog_CC="cc"
+      break
+    fi
+  done
+  IFS="$ac_save_ifs"
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# -gt 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    set dummy "$ac_dir/$ac_word" "$@"
+    shift
+    ac_cv_prog_CC="$@"
+  fi
+fi
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+  echo "$ac_t""$CC" 1>&6
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+  if test -z "$CC"; then
+    case "`uname -s`" in
+    *win32* | *WIN32*)
+      # Extract the first word of "cl", so it can be a program name with args.
+set dummy cl; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:897: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  IFS="${IFS=  }"; ac_save_ifs="$IFS"; IFS=":"
+  ac_dummy="$PATH"
+  for ac_dir in $ac_dummy; do
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$ac_word; then
+      ac_cv_prog_CC="cl"
+      break
+    fi
+  done
+  IFS="$ac_save_ifs"
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+  echo "$ac_t""$CC" 1>&6
+else
+  echo "$ac_t""no" 1>&6
+fi
+ ;;
+    esac
+  fi
+  test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
+fi
+
+echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
+echo "configure:929: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+cat > conftest.$ac_ext << EOF
+
+#line 940 "configure"
+#include "confdefs.h"
+
+main(){return(0);}
+EOF
+if { (eval echo configure:945: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  ac_cv_prog_cc_works=yes
+  # If we can't run a trivial program, we are probably using a cross compiler.
+  if (./conftest; exit) 2>/dev/null; then
+    ac_cv_prog_cc_cross=no
+  else
+    ac_cv_prog_cc_cross=yes
+  fi
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  ac_cv_prog_cc_works=no
+fi
+rm -fr conftest*
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
+if test $ac_cv_prog_cc_works = no; then
+  { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
+fi
+echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
+echo "configure:971: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
+cross_compiling=$ac_cv_prog_cc_cross
+
+echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
+echo "configure:976: checking whether we are using GNU C" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.c <<EOF
+#ifdef __GNUC__
+  yes;
+#endif
+EOF
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:985: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+  ac_cv_prog_gcc=yes
+else
+  ac_cv_prog_gcc=no
+fi
+fi
+
+echo "$ac_t""$ac_cv_prog_gcc" 1>&6
+
+if test $ac_cv_prog_gcc = yes; then
+  GCC=yes
+else
+  GCC=
+fi
+
+ac_test_CFLAGS="${CFLAGS+set}"
+ac_save_CFLAGS="$CFLAGS"
+CFLAGS=
+echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
+echo "configure:1004: checking whether ${CC-cc} accepts -g" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  echo 'void f(){}' > conftest.c
+if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
+  ac_cv_prog_cc_g=yes
+else
+  ac_cv_prog_cc_g=no
+fi
+rm -f conftest*
+
+fi
+
+echo "$ac_t""$ac_cv_prog_cc_g" 1>&6
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS="$ac_save_CFLAGS"
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+
+
+        echo $ac_n "checking for strerror in -lcposix""... $ac_c" 1>&6
+echo "configure:1037: checking for strerror in -lcposix" >&5
+ac_lib_var=`echo cposix'_'strerror | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-lcposix  $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 1045 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char strerror();
+
+int main() {
+strerror()
+; return 0; }
+EOF
+if { (eval echo configure:1056: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  LIBS="$LIBS -lcposix"
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+  
+
+
+
+
+echo $ac_n "checking for ${CC-cc} option to accept ANSI C""... $ac_c" 1>&6
+echo "configure:1082: checking for ${CC-cc} option to accept ANSI C" >&5
+if eval "test \"`echo '$''{'am_cv_prog_cc_stdc'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  am_cv_prog_cc_stdc=no
+ac_save_CC="$CC"
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX                  -qlanglvl=ansi
+# Ultrix and OSF/1     -std1
+# HP-UX                        -Aa -D_HPUX_SOURCE
+# SVR4                 -Xc -D__EXTENSIONS__
+for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  cat > conftest.$ac_ext <<EOF
+#line 1098 "configure"
+#include "confdefs.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+
+int main() {
+
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+
+; return 0; }
+EOF
+if { (eval echo configure:1135: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  rm -rf conftest*
+  am_cv_prog_cc_stdc="$ac_arg"; break
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+fi
+rm -f conftest*
+done
+CC="$ac_save_CC"
+
+fi
+
+if test -z "$am_cv_prog_cc_stdc"; then
+  echo "$ac_t""none needed" 1>&6
+else
+  echo "$ac_t""$am_cv_prog_cc_stdc" 1>&6
+fi
+case "x$am_cv_prog_cc_stdc" in
+  x|xno) ;;
+  *) CC="$CC $am_cv_prog_cc_stdc" ;;
+esac
+
+echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
+echo "configure:1159: checking how to run the C preprocessor" >&5
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+    # This must be in double quotes, not single quotes, because CPP may get
+  # substituted into the Makefile and "${CC-cc}" will confuse make.
+  CPP="${CC-cc} -E"
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp.
+  cat > conftest.$ac_ext <<EOF
+#line 1174 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1180: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  :
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  CPP="${CC-cc} -E -traditional-cpp"
+  cat > conftest.$ac_ext <<EOF
+#line 1191 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1197: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  :
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  CPP="${CC-cc} -nologo -E"
+  cat > conftest.$ac_ext <<EOF
+#line 1208 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1214: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  :
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  CPP=/lib/cpp
+fi
+rm -f conftest*
+fi
+rm -f conftest*
+fi
+rm -f conftest*
+  ac_cv_prog_CPP="$CPP"
+fi
+  CPP="$ac_cv_prog_CPP"
+else
+  ac_cv_prog_CPP="$CPP"
+fi
+echo "$ac_t""$CPP" 1>&6
+
+
+
+echo $ac_n "checking for function prototypes""... $ac_c" 1>&6
+echo "configure:1241: checking for function prototypes" >&5
+if test "$am_cv_prog_cc_stdc" != no; then
+  echo "$ac_t""yes" 1>&6
+  cat >> confdefs.h <<\EOF
+#define PROTOTYPES 1
+EOF
+
+  U= ANSI2KNR=
+else
+  echo "$ac_t""no" 1>&6
+  U=_ ANSI2KNR=./ansi2knr
+  # Ensure some checks needed by ansi2knr itself.
+  echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
+echo "configure:1254: checking for ANSI C header files" >&5
+if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1259 "configure"
+#include "confdefs.h"
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1267: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  rm -rf conftest*
+  ac_cv_header_stdc=yes
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+cat > conftest.$ac_ext <<EOF
+#line 1284 "configure"
+#include "confdefs.h"
+#include <string.h>
+EOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  egrep "memchr" >/dev/null 2>&1; then
+  :
+else
+  rm -rf conftest*
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+cat > conftest.$ac_ext <<EOF
+#line 1302 "configure"
+#include "confdefs.h"
+#include <stdlib.h>
+EOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  egrep "free" >/dev/null 2>&1; then
+  :
+else
+  rm -rf conftest*
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+if test "$cross_compiling" = yes; then
+  :
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1323 "configure"
+#include "confdefs.h"
+#include <ctype.h>
+#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int main () { int i; for (i = 0; i < 256; i++)
+if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
+exit (0); }
+
+EOF
+if { (eval echo configure:1334: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+then
+  :
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -fr conftest*
+  ac_cv_header_stdc=no
+fi
+rm -fr conftest*
+fi
+
+fi
+fi
+
+echo "$ac_t""$ac_cv_header_stdc" 1>&6
+if test $ac_cv_header_stdc = yes; then
+  cat >> confdefs.h <<\EOF
+#define STDC_HEADERS 1
+EOF
+
+fi
+
+  for ac_hdr in string.h
+do
+ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
+echo "configure:1361: checking for $ac_hdr" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1366 "configure"
+#include "confdefs.h"
+#include <$ac_hdr>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1371: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=yes"
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_hdr 1
+EOF
+else
+  echo "$ac_t""no" 1>&6
+fi
+done
+
+fi
+
+if test "x$U" != "x"; then
+       { echo "configure: error: Compiler not ANSI compliant" 1>&2; exit 1; }
+fi
+echo $ac_n "checking for inline""... $ac_c" 1>&6
+echo "configure:1403: checking for inline" >&5
+if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_cv_c_inline=no
+for ac_kw in inline __inline__ __inline; do
+  cat > conftest.$ac_ext <<EOF
+#line 1410 "configure"
+#include "confdefs.h"
+
+int main() {
+} $ac_kw foo() {
+; return 0; }
+EOF
+if { (eval echo configure:1417: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+  rm -rf conftest*
+  ac_cv_c_inline=$ac_kw; break
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+fi
+rm -f conftest*
+done
+
+fi
+
+echo "$ac_t""$ac_cv_c_inline" 1>&6
+case "$ac_cv_c_inline" in
+  inline | yes) ;;
+  no) cat >> confdefs.h <<\EOF
+#define inline 
+EOF
+ ;;
+  *)  cat >> confdefs.h <<EOF
+#define inline $ac_cv_c_inline
+EOF
+ ;;
+esac
+
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# ./install, which can be erroneously created by make from ./install.sh.
+echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
+echo "configure:1454: checking for a BSD compatible install" >&5
+if test -z "$INSTALL"; then
+if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+    IFS="${IFS=        }"; ac_save_IFS="$IFS"; IFS=":"
+  for ac_dir in $PATH; do
+    # Account for people who put trailing slashes in PATH elements.
+    case "$ac_dir/" in
+    /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
+    *)
+      # OSF1 and SCO ODT 3.0 have their own names for install.
+      # Don't use installbsd from OSF since it installs stuff as root
+      # by default.
+      for ac_prog in ginstall scoinst install; do
+        if test -f $ac_dir/$ac_prog; then
+         if test $ac_prog = install &&
+            grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
+           # AIX install.  It has an incompatible calling convention.
+           :
+         else
+           ac_cv_path_install="$ac_dir/$ac_prog -c"
+           break 2
+         fi
+       fi
+      done
+      ;;
+    esac
+  done
+  IFS="$ac_save_IFS"
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL="$ac_cv_path_install"
+  else
+    # As a last resort, use the slow shell script.  We don't cache a
+    # path for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the path is relative.
+    INSTALL="$ac_install_sh"
+  fi
+fi
+echo "$ac_t""$INSTALL" 1>&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
+echo "configure:1507: checking for ANSI C header files" >&5
+if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1512 "configure"
+#include "confdefs.h"
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1520: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  rm -rf conftest*
+  ac_cv_header_stdc=yes
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+cat > conftest.$ac_ext <<EOF
+#line 1537 "configure"
+#include "confdefs.h"
+#include <string.h>
+EOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  egrep "memchr" >/dev/null 2>&1; then
+  :
+else
+  rm -rf conftest*
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+cat > conftest.$ac_ext <<EOF
+#line 1555 "configure"
+#include "confdefs.h"
+#include <stdlib.h>
+EOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  egrep "free" >/dev/null 2>&1; then
+  :
+else
+  rm -rf conftest*
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+if test "$cross_compiling" = yes; then
+  :
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1576 "configure"
+#include "confdefs.h"
+#include <ctype.h>
+#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int main () { int i; for (i = 0; i < 256; i++)
+if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
+exit (0); }
+
+EOF
+if { (eval echo configure:1587: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+then
+  :
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -fr conftest*
+  ac_cv_header_stdc=no
+fi
+rm -fr conftest*
+fi
+
+fi
+fi
+
+echo "$ac_t""$ac_cv_header_stdc" 1>&6
+if test $ac_cv_header_stdc = yes; then
+  cat >> confdefs.h <<\EOF
+#define STDC_HEADERS 1
+EOF
+
+fi
+
+for ac_hdr in unistd.h locale.h termios.h linux/termios.h sys/ioctl.h
+do
+ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
+echo "configure:1614: checking for $ac_hdr" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1619 "configure"
+#include "confdefs.h"
+#include <$ac_hdr>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1624: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=yes"
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_hdr 1
+EOF
+else
+  echo "$ac_t""no" 1>&6
+fi
+done
+
+ac_safe=`echo "stdarg.h" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for stdarg.h""... $ac_c" 1>&6
+echo "configure:1652: checking for stdarg.h" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1657 "configure"
+#include "confdefs.h"
+#include <stdarg.h>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1662: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=yes"
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  cat >> confdefs.h <<\EOF
+#define HAVE_STDARG_H 1
+EOF
+
+else
+  echo "$ac_t""no" 1>&6
+{ echo "configure: error: *** stdarg.h is missing on your system ***" 1>&2; exit 1; }
+fi
+
+echo $ac_n "checking for working strcoll""... $ac_c" 1>&6
+echo "configure:1688: checking for working strcoll" >&5
+if eval "test \"`echo '$''{'ac_cv_func_strcoll_works'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  if test "$cross_compiling" = yes; then
+  ac_cv_func_strcoll_works=no
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1696 "configure"
+#include "confdefs.h"
+#include <string.h>
+main ()
+{
+  exit (strcoll ("abc", "def") >= 0 ||
+       strcoll ("ABC", "DEF") >= 0 ||
+       strcoll ("123", "456") >= 0);
+}
+EOF
+if { (eval echo configure:1706: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+then
+  ac_cv_func_strcoll_works=yes
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -fr conftest*
+  ac_cv_func_strcoll_works=no
+fi
+rm -fr conftest*
+fi
+
+fi
+
+echo "$ac_t""$ac_cv_func_strcoll_works" 1>&6
+if test $ac_cv_func_strcoll_works = yes; then
+  cat >> confdefs.h <<\EOF
+#define HAVE_STRCOLL 1
+EOF
+
+fi
+
+for ac_func in setlocale
+do
+echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
+echo "configure:1731: checking for $ac_func" >&5
+if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1736 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func(); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char $ac_func();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+$ac_func();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:1759: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_func_$ac_func=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_func_$ac_func=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_func 1
+EOF
+else
+  echo "$ac_t""no" 1>&6
+fi
+done
+
+
+
+abook_cv_curses=/usr
+# Check whether --with-curses or --without-curses was given.
+if test "${with_curses+set}" = set; then
+  withval="$with_curses"
+  if test $withval != yes; then
+               abook_cv_curses=$withval
+       fi
+       if test x$abook_cv_curses != x/usr; then
+               LDFLAGS="-L${abook_cv_curses}/lib $LDFLAGS"
+               CPPFLAGS="$CPPFLAGS -I${abook_cv_curses}/include"
+       fi
+fi
+
+
+echo $ac_n "checking for initscr in -lncurses""... $ac_c" 1>&6
+echo "configure:1800: checking for initscr in -lncurses" >&5
+ac_lib_var=`echo ncurses'_'initscr | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-lncurses  $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 1808 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char initscr();
+
+int main() {
+initscr()
+; return 0; }
+EOF
+if { (eval echo configure:1819: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  LIBS="$LIBS -lncurses"
+       if test x$abook_cv_curses = x/usr -a -d /usr/include/ncurses; then
+               CPPFLAGS="$CPPFLAGS -I/usr/include/ncurses"
+       fi
+       for ac_hdr in ncurses.h
+do
+ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
+echo "configure:1842: checking for $ac_hdr" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1847 "configure"
+#include "confdefs.h"
+#include <$ac_hdr>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1852: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=yes"
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_hdr 1
+EOF
+else
+  echo "$ac_t""no" 1>&6
+fi
+done
+
+else
+  echo "$ac_t""no" 1>&6
+
+echo $ac_n "checking for initscr""... $ac_c" 1>&6
+echo "configure:1882: checking for initscr" >&5
+if eval "test \"`echo '$''{'ac_cv_func_initscr'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1887 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char initscr(); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char initscr();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_initscr) || defined (__stub___initscr)
+choke me
+#else
+initscr();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:1910: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_func_initscr=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_func_initscr=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'initscr`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  :
+else
+  echo "$ac_t""no" 1>&6
+
+case $host_os in #(vi
+freebsd*) #(vi
+       echo $ac_n "checking for tgoto in -lmytinfo""... $ac_c" 1>&6
+echo "configure:1931: checking for tgoto in -lmytinfo" >&5
+ac_lib_var=`echo mytinfo'_'tgoto | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-lmytinfo  $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 1939 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char tgoto();
+
+int main() {
+tgoto()
+; return 0; }
+EOF
+if { (eval echo configure:1950: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  LIBS="-lmytinfo $LIBS"
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+       ;;
+hpux10.*|hpux11.*)
+       echo $ac_n "checking for initscr in -lcur_colr""... $ac_c" 1>&6
+echo "configure:1973: checking for initscr in -lcur_colr" >&5
+ac_lib_var=`echo cur_colr'_'initscr | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-lcur_colr  $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 1981 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char initscr();
+
+int main() {
+initscr()
+; return 0; }
+EOF
+if { (eval echo configure:1992: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  
+               LIBS="-lcur_colr $LIBS"
+               CFLAGS="-I/usr/include/curses_colr $CFLAGS"
+               ac_cv_func_initscr=yes
+               
+else
+  echo "$ac_t""no" 1>&6
+
+       echo $ac_n "checking for initscr in -lHcurses""... $ac_c" 1>&6
+echo "configure:2016: checking for initscr in -lHcurses" >&5
+ac_lib_var=`echo Hcurses'_'initscr | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-lHcurses  $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 2024 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char initscr();
+
+int main() {
+initscr()
+; return 0; }
+EOF
+if { (eval echo configure:2035: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  
+               # HP's header uses __HP_CURSES, but user claims _HP_CURSES.
+               LIBS="-lHcurses $LIBS"
+               CFLAGS="-D__HP_CURSES -D_HP_CURSES $CFLAGS"
+               ac_cv_func_initscr=yes
+               
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+fi
+
+       ;;
+linux*) # Suse Linux does not follow /usr/lib convention
+       LIBS="$LIBS -L/lib"
+       ;;
+esac
+
+if test ".$With5lib" != ".no" ; then
+if test -d /usr/5lib ; then
+       # SunOS 3.x or 4.x
+       CPPFLAGS="$CPPFLAGS -I/usr/5include"
+       LIBS="$LIBS -L/usr/5lib"
+fi
+fi
+
+if test ".$ac_cv_func_initscr" != .yes ; then
+       cf_save_LIBS="$LIBS"
+       cf_term_lib=""
+       cf_curs_lib=""
+
+       # Check for library containing tgoto.  Do this before curses library
+       # because it may be needed to link the test-case for initscr.
+       echo $ac_n "checking for tgoto""... $ac_c" 1>&6
+echo "configure:2084: checking for tgoto" >&5
+if eval "test \"`echo '$''{'ac_cv_func_tgoto'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 2089 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char tgoto(); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char tgoto();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_tgoto) || defined (__stub___tgoto)
+choke me
+#else
+tgoto();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:2112: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_func_tgoto=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_func_tgoto=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'tgoto`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  cf_term_lib=predefined
+else
+  echo "$ac_t""no" 1>&6
+
+               for cf_term_lib in termcap termlib unknown
+               do
+                       echo $ac_n "checking for tgoto in -l$cf_term_lib""... $ac_c" 1>&6
+echo "configure:2133: checking for tgoto in -l$cf_term_lib" >&5
+ac_lib_var=`echo $cf_term_lib'_'tgoto | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-l$cf_term_lib  $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 2141 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char tgoto();
+
+int main() {
+tgoto()
+; return 0; }
+EOF
+if { (eval echo configure:2152: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  break
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+               done
+       
+fi
+
+
+       # Check for library containing initscr
+       test "$cf_term_lib" != predefined && test "$cf_term_lib" != unknown && LIBS="-l$cf_term_lib $cf_save_LIBS"
+       for cf_curs_lib in cursesX curses ncurses xcurses jcurses unknown
+       do
+               echo $ac_n "checking for initscr in -l$cf_curs_lib""... $ac_c" 1>&6
+echo "configure:2182: checking for initscr in -l$cf_curs_lib" >&5
+ac_lib_var=`echo $cf_curs_lib'_'initscr | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-l$cf_curs_lib  $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 2190 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char initscr();
+
+int main() {
+initscr()
+; return 0; }
+EOF
+if { (eval echo configure:2201: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  break
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+       done
+       test $cf_curs_lib = unknown && { echo "configure: error: no curses library found" 1>&2; exit 1; }
+
+       LIBS="-l$cf_curs_lib $cf_save_LIBS"
+       if test "$cf_term_lib" = unknown ; then
+               echo $ac_n "checking if we can link with $cf_curs_lib library""... $ac_c" 1>&6
+echo "configure:2227: checking if we can link with $cf_curs_lib library" >&5
+               cat > conftest.$ac_ext <<EOF
+#line 2229 "configure"
+#include "confdefs.h"
+#include <${cf_cv_ncurses_header-curses.h}>
+int main() {
+initscr()
+; return 0; }
+EOF
+if { (eval echo configure:2236: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  cf_result=yes
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  cf_result=no
+fi
+rm -f conftest*
+               echo "$ac_t""$cf_result" 1>&6
+               test $cf_result = no && { echo "configure: error: Cannot link curses library" 1>&2; exit 1; }
+       elif test "$cf_term_lib" != predefined ; then
+               echo $ac_n "checking if we need both $cf_curs_lib and $cf_term_lib libraries""... $ac_c" 1>&6
+echo "configure:2250: checking if we need both $cf_curs_lib and $cf_term_lib libraries" >&5
+               cat > conftest.$ac_ext <<EOF
+#line 2252 "configure"
+#include "confdefs.h"
+#include <${cf_cv_ncurses_header-curses.h}>
+int main() {
+initscr(); tgoto((char *)0, 0, 0);
+; return 0; }
+EOF
+if { (eval echo configure:2259: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  cf_result=no
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  
+                       LIBS="-l$cf_curs_lib -l$cf_term_lib $cf_save_LIBS"
+                       cat > conftest.$ac_ext <<EOF
+#line 2269 "configure"
+#include "confdefs.h"
+#include <${cf_cv_ncurses_header-curses.h}>
+int main() {
+initscr()
+; return 0; }
+EOF
+if { (eval echo configure:2276: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  cf_result=yes
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  cf_result=error
+fi
+rm -f conftest*
+                       
+fi
+rm -f conftest*
+               echo "$ac_t""$cf_result" 1>&6
+       fi
+fi
+
+
+fi
+
+fi
+
+
+
+for ac_func in resizeterm
+do
+echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
+echo "configure:2303: checking for $ac_func" >&5
+if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 2308 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func(); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char $ac_func();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+$ac_func();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:2331: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_func_$ac_func=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_func_$ac_func=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_func 1
+EOF
+else
+  echo "$ac_t""no" 1>&6
+fi
+done
+
+
+echo $ac_n "checking for snprintf""... $ac_c" 1>&6
+echo "configure:2357: checking for snprintf" >&5
+if eval "test \"`echo '$''{'ac_cv_func_snprintf'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 2362 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char snprintf(); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char snprintf();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_snprintf) || defined (__stub___snprintf)
+choke me
+#else
+snprintf();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:2385: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_func_snprintf=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_func_snprintf=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'snprintf`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  cat >> confdefs.h <<\EOF
+#define HAVE_SNPRINTF 1
+EOF
+
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+echo $ac_n "checking for vsnprintf""... $ac_c" 1>&6
+echo "configure:2408: checking for vsnprintf" >&5
+if eval "test \"`echo '$''{'ac_cv_func_vsnprintf'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 2413 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char vsnprintf(); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char vsnprintf();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_vsnprintf) || defined (__stub___vsnprintf)
+choke me
+#else
+vsnprintf();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:2436: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_func_vsnprintf=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_func_vsnprintf=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'vsnprintf`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  cat >> confdefs.h <<\EOF
+#define HAVE_VSNPRINTF 1
+EOF
+
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+
+# Check whether --enable-debug or --disable-debug was given.
+if test "${enable_debug+set}" = set; then
+  enableval="$enable_debug"
+  case "${enableval}" in
+       yes) debug=true ;;
+       no) debug=false ;;
+       *) { echo "configure: error: bad value ${enableval} for --enable-debug" 1>&2; exit 1; } ;;
+       esac
+else
+  debug=false
+fi
+
+
+if test x$debug = xtrue; then
+       CPPFLAGS="-DDEBUG $CPPFLAGS"
+       CFLAGS="-g $CFLAGS"
+fi
+
+if test x$GCC = xyes; then
+       CFLAGS="-Wall $CFLAGS"
+fi
+
+trap '' 1 2 15
+cat > confcache <<\EOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs.  It is not useful on other systems.
+# If it contains results you don't want to keep, you may remove or edit it.
+#
+# By default, configure uses ./config.cache as the cache file,
+# creating it if it does not exist already.  You can give configure
+# the --cache-file=FILE option to use a different cache file; that is
+# what configure does when it calls configure scripts in
+# subdirectories, so they share the cache.
+# Giving --cache-file=/dev/null disables caching, for debugging configure.
+# config.status only pays attention to the cache file if you give it the
+# --recheck option to rerun configure.
+#
+EOF
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, don't put newlines in cache variables' values.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(set) 2>&1 |
+  case `(ac_space=' '; set | grep ac_space) 2>&1` in
+  *ac_space=\ *)
+    # `set' does not quote correctly, so add quotes (double-quote substitution
+    # turns \\\\ into \\, and sed turns \\ into \).
+    sed -n \
+      -e "s/'/'\\\\''/g" \
+      -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p"
+    ;;
+  *)
+    # `set' quotes correctly as required by POSIX, so do not add quotes.
+    sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p'
+    ;;
+  esac >> confcache
+if cmp -s $cache_file confcache; then
+  :
+else
+  if test -w $cache_file; then
+    echo "updating cache $cache_file"
+    cat confcache > $cache_file
+  else
+    echo "not updating unwritable cache $cache_file"
+  fi
+fi
+rm -f confcache
+
+trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# Any assignment to VPATH causes Sun make to only execute
+# the first set of double-colon rules, so remove it if not needed.
+# If there is a colon in the path, we need to keep it.
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[        ]*VPATH[        ]*=[^:]*$/d'
+fi
+
+trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15
+
+DEFS=-DHAVE_CONFIG_H
+
+# Without the "./", some shells look in PATH for config.status.
+: ${CONFIG_STATUS=./config.status}
+
+echo creating $CONFIG_STATUS
+rm -f $CONFIG_STATUS
+cat > $CONFIG_STATUS <<EOF
+#! /bin/sh
+# Generated automatically by configure.
+# Run this file to recreate the current configuration.
+# This directory was configured as follows,
+# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+#
+# $0 $ac_configure_args
+#
+# Compiler output produced by configure, useful for debugging
+# configure, is in ./config.log if it exists.
+
+ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]"
+for ac_option
+do
+  case "\$ac_option" in
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
+    exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
+  -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
+    echo "$CONFIG_STATUS generated by autoconf version 2.13"
+    exit 0 ;;
+  -help | --help | --hel | --he | --h)
+    echo "\$ac_cs_usage"; exit 0 ;;
+  *) echo "\$ac_cs_usage"; exit 1 ;;
+  esac
+done
+
+ac_given_srcdir=$srcdir
+ac_given_INSTALL="$INSTALL"
+
+trap 'rm -fr `echo "Makefile config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
+EOF
+cat >> $CONFIG_STATUS <<EOF
+
+# Protect against being on the right side of a sed subst in config.status.
+sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g;
+ s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF
+$ac_vpsub
+$extrasub
+s%@SHELL@%$SHELL%g
+s%@CFLAGS@%$CFLAGS%g
+s%@CPPFLAGS@%$CPPFLAGS%g
+s%@CXXFLAGS@%$CXXFLAGS%g
+s%@FFLAGS@%$FFLAGS%g
+s%@DEFS@%$DEFS%g
+s%@LDFLAGS@%$LDFLAGS%g
+s%@LIBS@%$LIBS%g
+s%@exec_prefix@%$exec_prefix%g
+s%@prefix@%$prefix%g
+s%@program_transform_name@%$program_transform_name%g
+s%@bindir@%$bindir%g
+s%@sbindir@%$sbindir%g
+s%@libexecdir@%$libexecdir%g
+s%@datadir@%$datadir%g
+s%@sysconfdir@%$sysconfdir%g
+s%@sharedstatedir@%$sharedstatedir%g
+s%@localstatedir@%$localstatedir%g
+s%@libdir@%$libdir%g
+s%@includedir@%$includedir%g
+s%@oldincludedir@%$oldincludedir%g
+s%@infodir@%$infodir%g
+s%@mandir@%$mandir%g
+s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
+s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g
+s%@INSTALL_DATA@%$INSTALL_DATA%g
+s%@PACKAGE@%$PACKAGE%g
+s%@VERSION@%$VERSION%g
+s%@ACLOCAL@%$ACLOCAL%g
+s%@AUTOCONF@%$AUTOCONF%g
+s%@AUTOMAKE@%$AUTOMAKE%g
+s%@AUTOHEADER@%$AUTOHEADER%g
+s%@MAKEINFO@%$MAKEINFO%g
+s%@SET_MAKE@%$SET_MAKE%g
+s%@host@%$host%g
+s%@host_alias@%$host_alias%g
+s%@host_cpu@%$host_cpu%g
+s%@host_vendor@%$host_vendor%g
+s%@host_os@%$host_os%g
+s%@CC@%$CC%g
+s%@CPP@%$CPP%g
+s%@U@%$U%g
+s%@ANSI2KNR@%$ANSI2KNR%g
+
+CEOF
+EOF
+
+cat >> $CONFIG_STATUS <<\EOF
+
+# Split the substitutions into bite-sized pieces for seds with
+# small command number limits, like on Digital OSF/1 and HP-UX.
+ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script.
+ac_file=1 # Number of current file.
+ac_beg=1 # First line for current file.
+ac_end=$ac_max_sed_cmds # Line after last line for current file.
+ac_more_lines=:
+ac_sed_cmds=""
+while $ac_more_lines; do
+  if test $ac_beg -gt 1; then
+    sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file
+  else
+    sed "${ac_end}q" conftest.subs > conftest.s$ac_file
+  fi
+  if test ! -s conftest.s$ac_file; then
+    ac_more_lines=false
+    rm -f conftest.s$ac_file
+  else
+    if test -z "$ac_sed_cmds"; then
+      ac_sed_cmds="sed -f conftest.s$ac_file"
+    else
+      ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file"
+    fi
+    ac_file=`expr $ac_file + 1`
+    ac_beg=$ac_end
+    ac_end=`expr $ac_end + $ac_max_sed_cmds`
+  fi
+done
+if test -z "$ac_sed_cmds"; then
+  ac_sed_cmds=cat
+fi
+EOF
+
+cat >> $CONFIG_STATUS <<EOF
+
+CONFIG_FILES=\${CONFIG_FILES-"Makefile"}
+EOF
+cat >> $CONFIG_STATUS <<\EOF
+for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case "$ac_file" in
+  *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
+       ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+  *) ac_file_in="${ac_file}.in" ;;
+  esac
+
+  # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
+
+  # Remove last slash and all that follows it.  Not all systems have dirname.
+  ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
+  if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
+    # The file is in a subdirectory.
+    test ! -d "$ac_dir" && mkdir "$ac_dir"
+    ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`"
+    # A "../" for each directory in $ac_dir_suffix.
+    ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'`
+  else
+    ac_dir_suffix= ac_dots=
+  fi
+
+  case "$ac_given_srcdir" in
+  .)  srcdir=.
+      if test -z "$ac_dots"; then top_srcdir=.
+      else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;;
+  /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
+  *) # Relative path.
+    srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
+    top_srcdir="$ac_dots$ac_given_srcdir" ;;
+  esac
+
+  case "$ac_given_INSTALL" in
+  [/$]*) INSTALL="$ac_given_INSTALL" ;;
+  *) INSTALL="$ac_dots$ac_given_INSTALL" ;;
+  esac
+
+  echo creating "$ac_file"
+  rm -f "$ac_file"
+  configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure."
+  case "$ac_file" in
+  *Makefile*) ac_comsub="1i\\
+# $configure_input" ;;
+  *) ac_comsub= ;;
+  esac
+
+  ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
+  sed -e "$ac_comsub
+s%@configure_input@%$configure_input%g
+s%@srcdir@%$srcdir%g
+s%@top_srcdir@%$top_srcdir%g
+s%@INSTALL@%$INSTALL%g
+" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file
+fi; done
+rm -f conftest.s*
+
+# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
+# NAME is the cpp macro being defined and VALUE is the value it is being given.
+#
+# ac_d sets the value in "#define NAME VALUE" lines.
+ac_dA='s%^\([  ]*\)#\([        ]*define[       ][      ]*\)'
+ac_dB='\([     ][      ]*\)[^  ]*%\1#\2'
+ac_dC='\3'
+ac_dD='%g'
+# ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
+ac_uA='s%^\([  ]*\)#\([        ]*\)undef\([    ][      ]*\)'
+ac_uB='\([     ]\)%\1#\2define\3'
+ac_uC=' '
+ac_uD='\4%g'
+# ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
+ac_eA='s%^\([  ]*\)#\([        ]*\)undef\([    ][      ]*\)'
+ac_eB='$%\1#\2define\3'
+ac_eC=' '
+ac_eD='%g'
+
+if test "${CONFIG_HEADERS+set}" != set; then
+EOF
+cat >> $CONFIG_STATUS <<EOF
+  CONFIG_HEADERS="config.h"
+EOF
+cat >> $CONFIG_STATUS <<\EOF
+fi
+for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case "$ac_file" in
+  *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
+       ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+  *) ac_file_in="${ac_file}.in" ;;
+  esac
+
+  echo creating $ac_file
+
+  rm -f conftest.frag conftest.in conftest.out
+  ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
+  cat $ac_file_inputs > conftest.in
+
+EOF
+
+# Transform confdefs.h into a sed script conftest.vals that substitutes
+# the proper values into config.h.in to produce config.h.  And first:
+# Protect against being on the right side of a sed subst in config.status.
+# Protect against being in an unquoted here document in config.status.
+rm -f conftest.vals
+cat > conftest.hdr <<\EOF
+s/[\\&%]/\\&/g
+s%[\\$`]%\\&%g
+s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp
+s%ac_d%ac_u%gp
+s%ac_u%ac_e%gp
+EOF
+sed -n -f conftest.hdr confdefs.h > conftest.vals
+rm -f conftest.hdr
+
+# This sed command replaces #undef with comments.  This is necessary, for
+# example, in the case of _POSIX_SOURCE, which is predefined and required
+# on some systems where configure will not decide to define it.
+cat >> conftest.vals <<\EOF
+s%^[   ]*#[    ]*undef[        ][      ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */%
+EOF
+
+# Break up conftest.vals because some shells have a limit on
+# the size of here documents, and old seds have small limits too.
+
+rm -f conftest.tail
+while :
+do
+  ac_lines=`grep -c . conftest.vals`
+  # grep -c gives empty output for an empty file on some AIX systems.
+  if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi
+  # Write a limited-size here document to conftest.frag.
+  echo '  cat > conftest.frag <<CEOF' >> $CONFIG_STATUS
+  sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS
+  echo 'CEOF
+  sed -f conftest.frag conftest.in > conftest.out
+  rm -f conftest.in
+  mv conftest.out conftest.in
+' >> $CONFIG_STATUS
+  sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail
+  rm -f conftest.vals
+  mv conftest.tail conftest.vals
+done
+rm -f conftest.vals
+
+cat >> $CONFIG_STATUS <<\EOF
+  rm -f conftest.frag conftest.h
+  echo "/* $ac_file.  Generated automatically by configure.  */" > conftest.h
+  cat conftest.in >> conftest.h
+  rm -f conftest.in
+  if cmp -s $ac_file conftest.h 2>/dev/null; then
+    echo "$ac_file is unchanged"
+    rm -f conftest.h
+  else
+    # Remove last slash and all that follows it.  Not all systems have dirname.
+      ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
+      if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
+      # The file is in a subdirectory.
+      test ! -d "$ac_dir" && mkdir "$ac_dir"
+    fi
+    rm -f $ac_file
+    mv conftest.h $ac_file
+  fi
+fi; done
+
+EOF
+cat >> $CONFIG_STATUS <<EOF
+
+
+EOF
+cat >> $CONFIG_STATUS <<\EOF
+test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h
+
+exit 0
+EOF
+chmod +x $CONFIG_STATUS
+rm -fr confdefs* $ac_clean_files
+test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1
+
+
diff --git a/configure.in b/configure.in
new file mode 100644 (file)
index 0000000..d99ded0
--- /dev/null
@@ -0,0 +1,70 @@
+dnl abook configure.in
+
+AC_INIT(abook.c)
+AM_INIT_AUTOMAKE(abook, 0.4.16)
+AM_CONFIG_HEADER(config.h)
+
+AC_CANONICAL_HOST
+
+AC_PROG_CC
+AC_ISC_POSIX
+AM_C_PROTOTYPES
+if test "x$U" != "x"; then
+       AC_MSG_ERROR(Compiler not ANSI compliant)
+fi
+AC_C_INLINE
+AC_PROG_INSTALL
+AC_HEADER_STDC
+AC_CHECK_HEADERS(unistd.h locale.h termios.h linux/termios.h sys/ioctl.h)
+AC_CHECK_HEADER(stdarg.h,AC_DEFINE(HAVE_STDARG_H),AC_MSG_ERROR([*** stdarg.h is missing on your system ***]))
+AC_FUNC_STRCOLL
+AC_CHECK_FUNCS(setlocale)
+
+dnl -------------------
+dnl (n)curses detection
+dnl -------------------
+
+abook_cv_curses=/usr
+AC_ARG_WITH(curses, [  --with-curses=DIR       Where ncurses is installed ],
+       [if test $withval != yes; then
+               abook_cv_curses=$withval
+       fi
+       if test x$abook_cv_curses != x/usr; then
+               LDFLAGS="-L${abook_cv_curses}/lib $LDFLAGS"
+               CPPFLAGS="$CPPFLAGS -I${abook_cv_curses}/include"
+       fi])
+
+AC_CHECK_LIB(ncurses, initscr,
+       [LIBS="$LIBS -lncurses"
+       if test x$abook_cv_curses = x/usr -a -d /usr/include/ncurses; then
+               CPPFLAGS="$CPPFLAGS -I/usr/include/ncurses"
+       fi
+       AC_CHECK_HEADERS(ncurses.h)],
+       [CF_CURSES_LIBS])
+
+dnl --------------------------
+dnl end of (n)curses detection
+dnl --------------------------
+
+AC_CHECK_FUNCS(resizeterm)
+
+AC_CHECK_FUNC(snprintf, [AC_DEFINE(HAVE_SNPRINTF)],)
+AC_CHECK_FUNC(vsnprintf, [AC_DEFINE(HAVE_VSNPRINTF)],)
+
+AC_ARG_ENABLE(debug, [  --enable-debug          Enable debugging support ], [case "${enableval}" in
+       yes) debug=true ;;
+       no) debug=false ;;
+       *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
+       esac], [debug=false])
+
+if test x$debug = xtrue; then
+       CPPFLAGS="-DDEBUG $CPPFLAGS"
+       CFLAGS="-g $CFLAGS"
+fi
+
+if test x$GCC = xyes; then
+       CFLAGS="-Wall $CFLAGS"
+fi
+
+AC_OUTPUT(Makefile)
+
diff --git a/contrib/abook+vim/README b/contrib/abook+vim/README
new file mode 100644 (file)
index 0000000..ad81c3a
--- /dev/null
@@ -0,0 +1,57 @@
+NOTE: There's no need to patch abook version 0.4.14 or later.
+NOTE2: The command in abook is 'Q' not 'P'.
+
+--- Original message from Brian Medley <brian.medley@verizon.net> ---
+Hi,
+
+I am trying to make abook work better (for me) within vim.  I am doing
+this because I have 'autoedit' and 'edit_headers' set in mutt.  This
+means I would like to have easy access to my abook addressbook (from
+within the editor).
+
+To accomplish this I have written a vim plugin (it will need vim 6.0)
+and have patched abook.  Both are included.  The patch is against abook
+0.4.13.
+
+Amongst other things, they allow me to obtain an address listing from
+abook and perform a mutt query using abook.  Below is an example.
+
+Suppose I have the following line (the cursor is at the caret):
+    To: 
+        ^
+I can now hit '\al' to lauch abook.  Once inside, I can highlight the
+people I want to email.  Then I hit 'P'.  Their email addresses now
+appear.  Next, suppose I have:
+    To: john
+            ^
+My plugin allows the command '\aq' to perform an alias mutt query using
+abook.  It uses the word under the cursor, so "john" will be looked up
+inside of abook.  Next, his email address will appear.  
+
+Summary:
+    \aq => alias query
+    \al => alias list
+
+Note:
+    - \ is actually LocalLeader
+    - I am aware that abook can do these things from within *mutt*, but
+      I want to do them from within vim.
+    - This plugin does other stuff, as well (like deleting signatures,
+      and positioning the cursor when you start) because I stole code
+      from Cedric Duval's mail vimrc.
+    - Improvements / comments are welcome.
+
+Todo:
+    - Documentation :)
+    - I tried to write this so that another alias query program could be
+      used (e.g. ldap), but I have not implemented this.  
+
+Bugs:
+    - I had trouble getting this to work in gvim.  I used vim in a
+      console.
+
+Basic Installation:
+    - patch and install abook
+    - place the mail.vim plugin in ~/.vim/after/ftplugin
+
+--- ---
diff --git a/contrib/abook+vim/mail.vim b/contrib/abook+vim/mail.vim
new file mode 100644 (file)
index 0000000..bdc3134
--- /dev/null
@@ -0,0 +1,530 @@
+" mail FTplugin
+"
+" Requires vim 6.x.  
+" To install place in ~/.vim/after/ftplugin/mail.vim
+"
+" Author: Brian Medley
+" Email:  freesoftware@4321.tv
+"
+" This file was modified from Cedric Duval's version.
+" http://cedricduval.free.fr/download/vimrc/mail
+
+" Only do this when not done yet for this buffer
+if exists("b:did_mail_after_ftplugin")
+  finish
+endif
+let b:did_mail_after_ftplugin = 1
+
+if !exists ("mail_alias_program")
+    let mail_alias_program="Abook"
+endif
+
+" ====================================================================
+"                               Globals
+" ====================================================================
+
+if !exists ("mail_quote_chars")
+    let s:quote_chars = ':!|>'
+else
+    let s:quote_chars = mail_quote_chars
+endif
+
+" This re defines a 'quote'
+let s:quote_re = '\(\s\?\w*[' . s:quote_chars . ']\)'
+"                   \s\?                             => 0 or one whitespace char 
+"                                                       (b/c some ppl put
+"                                                       spaces in the quote,
+"                                                       and others don't)
+"                                                   
+"                       \w*                          => maybe word chars (b/c
+"                                                       some ppl put initals in
+"                                                       the quotes)
+"                               the rest             => actual quote chars 
+"                 \(                              \) => this is a quote "level"
+
+" This re defines the quoting level at the *beginning* of a line
+let s:quote_start = '^' . s:quote_re . s:quote_re . '*'
+"                    ^s:quote_re                        => quote at beginning of
+"                                                          line
+"                                      s:quote_re*      => perhaps followed by
+"                                                          more quotes
+
+" For debugging:
+" let b:quote_chars = s:quote_chars
+" let b:quote_re = s:quote_re
+" let b:quote_start = s:quote_start
+
+" ====================================================================
+"                               Mappings
+" ====================================================================
+
+if !exists("no_plugin_maps") && !exists("no_mail_maps")
+    
+    "
+    " get alias list mappings
+    " 
+    if !hasmapto('<Plug>MailAliasList', 'n')
+        nmap <buffer> <unique> <LocalLeader>al  <Plug>MailAliasList
+    endif
+    if !hasmapto('<Plug>MailAliasList', 'i')
+        imap <buffer> <unique> <LocalLeader>al  <Plug>MailAliasList
+    endif
+    
+    nnoremap <buffer> <unique> <script> <Plug>MailAliasList <SID>AliasList
+    inoremap <buffer> <unique> <script> <Plug>MailAliasList <SID>AliasList
+    
+    " Redraw is there b/c my screen was messed up after abook finished.
+    " The 'set paste' is in the function b/c I couldn't figure out how to put it in
+    "   the mapping.
+    " The 'set nopaste' is in the mapping b/c it didn't work for me in the script.
+    nnoremap <buffer> <SID>AliasList A<c-r>=<SID>AliasList{mail_alias_program}()<cr><c-o>:set nopaste<cr><c-o>:redraw!<cr><c-o>:echo b:AliasListMsg<cr><esc>
+    inoremap <buffer> <SID>AliasList  <c-r>=<SID>AliasList{mail_alias_program}()<cr><c-o>:set nopaste<cr><c-o>:redraw!<cr><c-o>:echo b:AliasListMsg<cr>
+
+    "
+    " get alias query mappings
+    "
+    if !hasmapto('<Plug>MailAliasQuery', 'n')
+        nmap <buffer> <unique> <LocalLeader>aq  <Plug>MailAliasQuery
+    endif
+    if !hasmapto('<Plug>MailAliasQuery', 'i')
+        imap <buffer> <unique> <LocalLeader>aq  <Plug>MailAliasQuery
+    endif
+    
+    nnoremap <buffer> <unique> <script> <Plug>MailAliasQuery <SID>AliasQuery
+    inoremap <buffer> <unique> <script> <Plug>MailAliasQuery <SID>AliasQuery
+    
+    nnoremap <buffer> <SID>AliasQuery      :call <SID>AliasQuery{mail_alias_program}()<cr>:echo b:AliasQueryMsg<cr>
+    inoremap <buffer> <SID>AliasQuery <c-o>:call <SID>AliasQuery{mail_alias_program}()<cr><c-o>:echo b:AliasQueryMsg<cr><right>
+
+    " 
+    " mail formatting mappings
+    "
+
+    " * <F1> to re-format a quotelvl
+    " * <F2> to format a line which is too long, and go to the next line
+    " * <F3> to merge the previous line with the current one, with a correct
+    "        formatting (sometimes useful associated with <F2>)
+    " * <F4> to re-format the current paragraph correctly
+
+    if !hasmapto('<Plug>MailFormatQuoteLvl', 'n')
+        nmap <buffer> <unique> <F1> <Plug>MailFormatQuoteLvl
+    endif
+    if !hasmapto('<Plug>MailFormatLine', 'n')
+        nmap <buffer> <unique> <F2> <Plug>MailFormatLine
+    endif
+    if !hasmapto('<Plug>MailFormatMerge', 'n')
+        nmap <buffer> <unique> <F3> <Plug>MailFormatMerge
+    endif
+    if !hasmapto('<Plug>MailFormatParagraph', 'n')
+        nmap <buffer> <unique> <F4> <Plug>MailFormatParagraph
+    endif
+
+    if !hasmapto('<Plug>MailFormatQuoteLvl', 'i')
+        imap <buffer> <unique> <F1> <Plug>MailFormatQuoteLvl
+    endif
+    if !hasmapto('<Plug>MailFormatLine', 'i')
+        imap <buffer> <unique> <F2> <Plug>MailFormatLine
+    endif
+    if !hasmapto('<Plug>MailFormatMerge', 'i')
+        imap <buffer> <unique> <F3> <Plug>MailFormatMerge
+    endif
+    if !hasmapto('<Plug>MailFormatParagraph', 'i')
+        imap <buffer> <unique> <F4> <Plug>MailFormatParagraph
+    endif
+
+    nnoremap <buffer> <unique> <script> <Plug>MailFormatQuoteLvl  <SID>FormatQuoteLvl
+    nnoremap <buffer> <unique> <script> <Plug>MailFormatLine      <SID>FormatLine
+    nnoremap <buffer> <unique> <script> <Plug>MailFormatMerge     <SID>FormatMerge
+    nnoremap <buffer> <unique> <script> <Plug>MailFormatParagraph <SID>FormatParagraph
+    inoremap <buffer> <unique> <script> <Plug>MailFormatQuoteLvl  <SID>FormatQuoteLvl
+    inoremap <buffer> <unique> <script> <Plug>MailFormatLine      <SID>FormatLine
+    inoremap <buffer> <unique> <script> <Plug>MailFormatMerge     <SID>FormatMerge
+    inoremap <buffer> <unique> <script> <Plug>MailFormatParagraph <SID>FormatParagraph
+
+    nnoremap <buffer> <script> <SID>FormatQuoteLvl  gq<SID>QuoteLvlMotion
+    nnoremap <buffer>          <SID>FormatLine      gqqj
+    nnoremap <buffer>          <SID>FormatMerge     kgqj
+    nnoremap <buffer>          <SID>FormatParagraph gqap
+    inoremap <buffer> <script> <SID>FormatQuoteLvl  <ESC>gq<SID>QuoteLvlMotioni
+    inoremap <buffer>          <SID>FormatLine      <ESC>gqqji
+    inoremap <buffer>          <SID>FormatMerge     <ESC>kgqji
+    inoremap <buffer>          <SID>FormatParagraph <ESC>gqapi
+
+    " 
+    " sig removal mappings
+    "
+    if !hasmapto('<Plug>MailEraseQuotedSig', 'n')
+        nmap <silent> <buffer> <unique> <LocalLeader>eqs <Plug>MailEraseQuotedSig
+    endif
+    nnoremap <buffer> <unique> <script> <Plug>MailEraseQuotedSig <SID>EraseQuotedSig
+    nnoremap <buffer> <SID>EraseQuotedSig :call<SID>EraseQuotedSig()<CR>
+
+    "
+    " Provide a motion operator for commands (so you can delete a quote
+    " segment, or format quoted segment)
+    "
+    if !hasmapto('<Plug>MailQuoteLvlMotion', 'o')
+        omap <silent> <buffer> <unique> q <Plug>MailQuoteLvlMotion
+    endif
+    onoremap <buffer> <unique> <script> <Plug>MailQuoteLvlMotion <SID>QuoteLvlMotion
+    onoremap <buffer> <script> <SID>QuoteLvlMotion :execute "normal!" . <SID>QuoteLvlMotion(line("."))<cr>
+    
+endif
+
+" ====================================================================
+"                     Mail Manipulation Functions
+" ====================================================================
+
+" --------------------------------------------------------------------
+"                          Manipulate Quotes
+" --------------------------------------------------------------------
+
+"
+" Description: 
+" This function will try and remove 'quoted' signatures.
+"
+" If someone responds with an email that doesn't use '>' as the
+" quote character this will try and take care of that:
+"   | Yeah, I agree vim is cool.
+"   | 
+"   | -- 
+"   | Some power user
+"
+" If there is a signature inside a 'multi-quoted' email this will try and get
+" rid of it:
+"   > | No, I don't agree with you.
+"   >
+"   > Nonsense.  You are wrong.  Grow up.
+"   >
+"   > | I can't believe I'm even replying to this.
+"   > | -- 
+"   > | Some power user
+"   >
+"   > Yeah, believe it, brother.
+" 
+if !exists("*s:EraseQuotedSig")
+function s:EraseQuotedSig()
+    while 0 != search((s:quote_start . '\s*--\s*$'), 'w')
+        let motion = s:QuoteLvlMotion(line("."))
+        exe "normal! d" . motion
+    endwhile
+endfunction
+endif
+
+"
+" Description:
+" Replacing empty quoted lines (i.e. "> $") with empty lines
+" (convenient to automatically reformat one paragraph)
+"
+if !exists("*s:DelEmptyQuoted")
+function s:DelEmptyQuoted()
+    let empty_quote = s:quote_start . '\s*$'
+
+    " goto start of email and jump passed headers
+    normal gg
+    if 0 == search('^$', 'W')
+        return
+    endif
+    
+    while 0 != search (empty_quote, 'W')
+        let newline = substitute(getline("."), empty_quote, '', '')
+        call setline(line("."), newline)
+    endwhile
+endfunction
+endif
+
+"
+" Description:
+" This function will output a motion command that operatates over a "quote
+" level" segment.  This makes it possible to perform vi commands on quotes.
+" E.g:
+"   dq  => delete an entire quote section
+"   gqq => format an entire quote section
+"
+if !exists("*s:QuoteLvlMotion")
+function s:QuoteLvlMotion(line)
+    let quote = matchstr(getline(a:line), s:quote_start)
+    " abort command if no quote
+    if "" == quote
+        return "\<esc>"
+    endif
+        
+    let len = s:LenQuoteLvl(a:line, quote)
+
+    " the 'V' makes the motion linewise
+    if 1 == len
+        return "V" . line(".") . "G"
+    else
+        return "V" . (len - 1) . "j"
+    endif
+endfunction
+endif
+
+"
+" Description:
+" This tries to figure out when the quoting level changes
+"
+if !exists("s:LenQuoteLvl")
+function s:LenQuoteLvl(start, quote)
+    let i = a:start + 1
+    let len = 1
+    let quote = '^' . a:quote
+    
+    " find end of quote
+    while i <= line('$')
+        " check if quote level decreased
+        if -1 == match(getline(i), quote)
+            break
+        endif
+
+        " check if quote level increased
+        if -1 != match(getline(i), (quote . s:quote_re))
+            break
+        endif
+        
+        let i   = i   + 1 
+        let len = len + 1
+    endwhile
+
+    return len
+endfunction
+endif
+
+" --------------------------------------------------------------------
+"                    Location Manipulator Functions
+" --------------------------------------------------------------------
+
+"
+" Description:
+" Moves the cursor to a 'sensible' position.
+" 
+if !exists("*s:CursorStart")
+function s:CursorStart()
+    " put cursor in known position
+    silent normal gg
+    
+    if search('^From: $', 'W')
+        silent startinsert!
+    elseif search('^To: $', 'W')
+        silent startinsert!
+    elseif search('^Subject: $', 'W')
+        silent startinsert!
+        
+    " check if we are editing a reply
+    elseif search('^On.*wrote:', 'W')
+        normal 2j
+        
+    elseif search('^$', 'W')
+        normal j
+        silent startinsert!
+    endif
+endfunction
+endif
+
+" ================================================
+"               Process Mutt Aliases
+" ================================================
+
+" ------------------------------------------------
+"                  Get Email List
+" ------------------------------------------------
+
+"
+" Description:
+" This function will launch abook and spit out what the user selected from the
+" application (by pressing 'Q').  It's always called from 'insert' mode, so
+" the text will be inserted like it was typed.
+"
+" That's why 'paste' is set and reset.  So that the text that we insert won't
+" be 'mangled' by the user's settings.
+"
+if !exists("*s:AliasListAbook")
+function s:AliasListAbook()
+    let b:AliasListMsg = ""
+    let f = tempname()
+
+    set paste
+    silent exe '!abook 2> ' . f
+    exe 'let addresses=system("cat ' . f . '")'
+    if "" == addresses
+        let b:AliasListMsg = "Nothing found to lookup"
+        return ""
+    endif
+
+    " - parses the output from abook
+    let addresses=s:ParseMuttQuery(addresses)
+    if "" == addresses
+        let b:AliasListMsg = b:ParseMuttQueryErr
+        return ""
+    endif
+
+    " so that they will be aligned under the 'to' or 'cc' line
+    let addresses=substitute(addresses, "\n", ",\n    ", "g")
+
+    return addresses
+endfunction
+endif
+
+" ------------------------------------------------
+"                 Get Email Query
+" ------------------------------------------------
+
+"
+" Description:
+" This function assumes that user has the cursor on an alias to lookup.  Based
+" on this it:
+" - retrieves the alias(es) from abook
+" - parses the output from abook
+" - actually replaces the alias with the parsed output
+"
+if !exists("*s:AliasQueryAbook")
+function s:AliasQueryAbook()
+    let b:AliasQueryMsg = ""
+
+    " - retrieves the alias(es) from abook
+    let lookup=expand("<cword>")
+    if "" == lookup
+        let b:AliasQueryMsg = "Nothing found to lookup"
+        return
+    endif
+
+    silent exe 'let output=system("abook --mutt-query ' . lookup . '")'
+    if v:shell_error
+        let b:AliasQueryMsg = output
+        return
+    endif
+
+    " - parses the output from abook
+    let replacement=s:ParseMuttQuery(output)
+    if "" == replacement
+        let b:AliasQueryMsg = b:ParseMuttQueryErr
+        return
+    endif
+
+    " so that they will be aligned under the 'to' or 'cc' line
+    let replacement=substitute(replacement, "\n", ",\n    ", "g")
+
+    " - actually replaces the alias with the parsed output
+    " paste is set/unset so that the email addresses aren't "mangled" by the
+    " user's formating options
+    set paste
+    exe "normal! ciw" . replacement . "\<Esc>"
+    set nopaste
+endfunction
+endif
+
+" --------------------------------------------------------------------
+"                          Utility Functions
+" --------------------------------------------------------------------
+
+"
+" Description:
+" This function will take the output of a "mutt query" (as defined by the mutt
+" documenation) and parses it.  
+"
+" It returns the email addresses formatted as follows:
+" - each address is on a line
+"
+if !exists("*s:ParseMuttQuery")
+function s:ParseMuttQuery(aliases)
+    " remove first informational line
+    let aliases   = substitute (a:aliases, "\n", "", "")
+    let expansion = ""
+
+    while 1
+        " whip off the name and address
+        let line    = matchstr(aliases, ".\\{-}\n")
+        let address = matchstr(line, ".\\{-}\t")
+        let address = substitute(address, "\t", "", "g")
+        if "" == address
+            let b:ParseMuttQueryErr = "Unable to parse address from ouput"
+            return ""
+        endif
+
+        let name = matchstr(line, "\t.*\t")
+        let name = substitute(name, "\t", "", "g")
+        if "" == name
+            let b:ParseMuttQueryErr = "Unable to parse name from ouput"
+            return ""
+        endif
+
+        " debugging:
+        " echo "line: " . line . "|"
+        " echo "address: " . address . "|"
+        " echo "name: " . name . "|"
+        " let a=input("hit enter")
+
+        " make into valid email address
+        let needquote = match (name, '"')
+        if (-1 == needquote)
+            let name = '"' . name    . '" '
+        endif
+        
+        let needquote = match (address, '<')
+        if (-1 == needquote)
+            let address = '<' . address . '>'
+        endif
+        
+        " add email address to list
+        let expansion = expansion . name
+        let expansion = expansion . address
+
+        " debugging:
+        " echo "address: " . address . "|"
+        " echo "name: " . name . "|"
+        " let a=input("hit enter")
+        
+        " process next line (if there is one)
+        let aliases = substitute(aliases, ".\\{-}\n", "", "")
+        if "" == aliases
+            let b:ParseMuttQueryErr = ""
+            return expansion
+        endif
+
+        let expansion = expansion . "\n"
+    endwhile
+endfunction
+endif
+
+" ====================================================================
+"                      Abbreviation Manipulation
+" ====================================================================
+
+"
+" Description:
+" This will generate vi abbreviations from your mutt alias file.
+" 
+" Note:
+" However, remember that the abbreviation will be replaced *everywhere*.  For
+" example, if you have the alias 'Mary', then if you try and type "Hi, Mary
+" vim is cool", then it won't work.  This is because the 'Mary' will be
+" expanded as an alias.
+"
+if !exists("*s:MakeAliasAbbrev")
+function s:MakeAliasAbbrev()
+    let aliasfile = tempname()
+    silent exe "!sed -e 's/alias/iab/' ~/.mutt/aliases > " . aliasfile
+    exe "source " . aliasfile
+endfunction
+endif
+
+
+" ====================================================================
+"                           Initializations
+" ====================================================================
+
+if exists ("mail_erase_quoted_sig")
+    call s:EraseQuotedSig()
+endif
+
+if exists ("mail_delete_empty_quoted")
+    call s:DelEmptyQuoted()
+endif
+
+if exists ("mail_generate_abbrev")
+    call s:MakeAliasAbbrev()
+endif
+
+if exists ("mail_cursor_start")
+    call s:CursorStart()
+endif
diff --git a/contrib/epm/README b/contrib/epm/README
new file mode 100644 (file)
index 0000000..fc8e95f
--- /dev/null
@@ -0,0 +1,14 @@
+Hi
+I've written a list file (+ configure.in small mods) that can be used with
+epm (www.easysw.com) to generate packages for almost all unixes. I find it
+useful when switching between solaris, freebsd and linux. Hope it can be of
+some help.
+
+--
+        Giuseppe "Cowo" Corbelli ~\/~ My software: http://cowo.mascanc.net
+          -<! windoze: no need of an hammer to crash it! !>-
+
+
+* * *
+
+NOTE: Please adjust version numbers in configure.in manually
diff --git a/contrib/epm/abook.list.in b/contrib/epm/abook.list.in
new file mode 100644 (file)
index 0000000..9f7e70c
--- /dev/null
@@ -0,0 +1,51 @@
+# abooklist file
+# tested with epm 3.1.0 and abook @MAJOR@.@MINOR@.@PATCHLEVEL@
+
+# Directories...
+$prefix=@prefix@
+$bindir=@prefix@/bin
+$confdir=@sysconfdir@
+$mandir=@mandir@
+$srcdir=@top_srcdir@
+$docdir=@datadir@/abook-@MAJOR@.@MINOR@.@PATCHLEVEL@
+
+# Product information
+%product abook 
+%copyright GPL
+%vendor Jaakko Heinonen <jheinonen@users.sourceforge.net> 
+%license ${srcdir}/COPYING
+%readme ${srcdir}/README
+%description Abook is an addressbook program with mutt mail client support.
+%version @MAJOR@.@MINOR@.@PATCHLEVEL@
+%packager Giuseppe "Cowo" Corbelli <cowo@lugbs.linux.it>
+
+d 0755 root sys $bindir/ -
+f 0755 root sys $bindir/abook $srcdir/abook
+d 0755 root sys $mandir -
+d 0755 root sys $mandir/man1 -
+f 0644 root sys $mandir/man1/abook.1 $srcdir/abook.1
+d 0755 root sys $mandir/man5 -
+f 0644 root sys $mandir/man5/abookrc.5 $srcdir/abookrc.5
+d 0755 root sys $docdir -
+f 0644 root sys $docdir/AUTHORS $srcdir/AUTHORS
+f 0644 root sys $docdir/BUGS $srcdir/BUGS
+f 0644 root sys $docdir/ChangeLog $srcdir/ChangeLog
+f 0644 root sys $docdir/FAQ $srcdir/FAQ
+f 0644 root sys $docdir/NEWS $srcdir/NEWS
+f 0644 root sys $docdir/README $srcdir/README
+f 0644 root sys $docdir/THANKS $srcdir/THANKS
+f 0644 root sys $docdir/TODO $srcdir/TODO
+f 0644 root sys $docdir/sample.abookrc $srcdir/sample.abookrc
+d 0755 root sys $docdir/contrib -
+f 0755 root sys $docdir/contrib/mail2abook.py contrib/mail2abook.py
+f 0755 root sys $docdir/contrib/vcard2abook.pl contrib/vcard2abook.pl
+d 0755 root sys $docdir/contrib/abook+vim -
+f 0644 root sys $docdir/contrib/abook+vim/README contrib/abook+vim/README
+f 0644 root sys $docdir/contrib/abook+vim/mail.vim contrib/abook+vim/mail.vim
+d 0755 root sys $docdir/contrib/whitelist -
+f 0644 root sys $docdir/contrib/whitelist/README contrib/whitelist/README
+f 0755 root sys $docdir/contrib/whitelist/abook2whitelist.sh contrib/whitelist/abook2whitelist.sh
+f 0644 root sys $docdir/contrib/whitelist/mutt.whitelist contrib/whitelist/mutt.whitelist
+f 0644 root sys $docdir/contrib/whitelist/patch.orig.obsolete contrib/whitelist/patch.orig.obsolete
+f 0744 root sys $docdir/contrib/whitelist/whitelist.rc contrib/whitelist/whitelist.rc
+
diff --git a/contrib/epm/configure.in b/contrib/epm/configure.in
new file mode 100644 (file)
index 0000000..68f50c6
--- /dev/null
@@ -0,0 +1,76 @@
+dnl abook configure.in
+
+AC_INIT(abook.c)
+AM_INIT_AUTOMAKE(abook, 0.4.14)
+AM_CONFIG_HEADER(config.h)
+
+AC_CANONICAL_HOST
+
+MAJOR=0
+MINOR=4
+PATCHLEVEL=14
+AC_SUBST(MAJOR)
+AC_SUBST(MINOR)
+AC_SUBST(PATCHLEVEL)
+
+AC_PROG_CC
+AC_ISC_POSIX
+AM_C_PROTOTYPES
+if test "x$U" != "x"; then
+       AC_MSG_ERROR(Compiler not ANSI compliant)
+fi
+AC_C_INLINE
+AC_PROG_INSTALL
+AC_HEADER_STDC
+AC_CHECK_HEADERS(unistd.h locale.h termios.h linux/termios.h sys/ioctl.h)
+AC_CHECK_HEADER(stdarg.h,AC_DEFINE(HAVE_STDARG_H),AC_MSG_ERROR([*** stdarg.h is missing on your system ***]))
+AC_CHECK_FUNCS(setlocale)
+
+dnl -------------------
+dnl (n)curses detection
+dnl -------------------
+
+abook_cv_curses=/usr
+AC_ARG_WITH(curses, [  --with-curses=DIR       Where ncurses is installed ],
+       [if test $withval != yes; then
+               abook_cv_curses=$withval
+       fi
+       if test x$abook_cv_curses != x/usr; then
+               LDFLAGS="-L${abook_cv_curses}/lib $LDFLAGS"
+               CPPFLAGS="$CPPFLAGS -I${abook_cv_curses}/include"
+       fi])
+
+AC_CHECK_LIB(ncurses, initscr,
+       [LIBS="$LIBS -lncurses"
+       if test x$abook_cv_curses = x/usr -a -d /usr/include/ncurses; then
+               CPPFLAGS="$CPPFLAGS -I/usr/include/ncurses"
+       fi
+       AC_CHECK_HEADERS(ncurses.h)],
+       [CF_CURSES_LIBS])
+
+dnl --------------------------
+dnl end of (n)curses detection
+dnl --------------------------
+
+AC_CHECK_FUNCS(resizeterm)
+
+AC_CHECK_FUNC(snprintf, [AC_DEFINE(HAVE_SNPRINTF)],)
+AC_CHECK_FUNC(vsnprintf, [AC_DEFINE(HAVE_VSNPRINTF)],)
+
+AC_ARG_ENABLE(debug, [  --enable-debug          Enable debugging support ], [case "${enableval}" in
+       yes) debug=true ;;
+       no) debug=false ;;
+       *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
+       esac], [debug=false])
+
+if test x$debug = xtrue; then
+       CPPFLAGS="-DDEBUG $CPPFLAGS"
+       CFLAGS="-g $CFLAGS"
+fi
+
+if test x$GCC = xyes; then
+       CFLAGS="-Wall $CFLAGS"
+fi
+
+AC_OUTPUT(Makefile abook.list)
+
diff --git a/contrib/epm/configure.in.patch b/contrib/epm/configure.in.patch
new file mode 100644 (file)
index 0000000..eeb8e34
--- /dev/null
@@ -0,0 +1,29 @@
+--- ../../configure.in Wed Oct 10 21:35:54 2001
++++ configure.in       Wed Oct 10 04:52:33 2001
+@@ -1,11 +1,18 @@
+ dnl abook configure.in
+ AC_INIT(abook.c)
+-AM_INIT_AUTOMAKE(abook, 0.4.15pre2)
++AM_INIT_AUTOMAKE(abook, 0.4.14)
+ AM_CONFIG_HEADER(config.h)
+ AC_CANONICAL_HOST
++MAJOR=0
++MINOR=4
++PATCHLEVEL=14
++AC_SUBST(MAJOR)
++AC_SUBST(MINOR)
++AC_SUBST(PATCHLEVEL)
++
+ AC_PROG_CC
+ AC_ISC_POSIX
+ AM_C_PROTOTYPES
+@@ -65,5 +72,5 @@
+       CFLAGS="-Wall $CFLAGS"
+ fi
+-AC_OUTPUT(Makefile)
++AC_OUTPUT(Makefile abook.list)
diff --git a/contrib/mail2abook.py b/contrib/mail2abook.py
new file mode 100755 (executable)
index 0000000..cfb3af5
--- /dev/null
@@ -0,0 +1,436 @@
+#!/usr/bin/env python
+
+# NOTE: starting from abook version 0.4.15 it is often more convenient
+# to use command line option "--add-email" instead of this script
+
+# mail2abook.py version 0.1pre4
+# by Jaakko Heinonen <jheinonen@users.sourceforge.net>
+# based on Moritz Moeller-Herrmann's mail2muttalias.py
+
+# Description:
+# this script reads all mail adresses from a piped mailfile and
+# offers to write them to the ABOOKFILE specified in the script
+# Append the following lines or similiar to your muttrc:
+# macro pager A |'path to script'/mail2abook.py\n
+
+# Then press A in pager mode to add an address to your abook addressbook
+
+# Here's the original copyright information:
+
+# RELEASE 0.5
+##
+# Needs python 1.5 and cursesmodule 1.4 by andrich@fga.de (Oliver Andrich)   
+# available somewhere on http://www.python.org or directly from
+# http://andrich.net/python/selfmade.html
+#
+# Copyright by Moritz Moeller-Herrmann <mmh@gmnx.net>
+#
+# Homepage (check for changes before reporting a bug)
+# http://webrum.uni-mannheim.de/jura/moritz/mail2muttalias.html 
+#
+# Use this any way you want. Please inform me of any error/improvement
+# and leave the copyright notice untouched.
+# No warranties, as this is my first program :-)
+# Works for me on Linux with Python 1.5+
+# 
+# Thanks to Josh Hildebrand for some improvements
+##
+
+# Known bugs: 
+# If name containing @ is quoted("") before a mail adress, 
+# the program will not catch the whole name, 
+# but who would alias such an idiot?
+# If you get a problem with "unknown variable / keyword error" 
+# with KEYUP and KEYDOWN, either get a newer pythoncurses module 
+# or change them to lowercase.
+#
+# Probably some more, mail me if you find one!
+
+import re 
+import string, sys, os 
+import curses, traceback
+
+
+ABOOKFILE=os.environ["HOME"] + "/.abook.addressbook"
+
+try :
+       testcurses = curses.KEY_UP
+except NameError:
+       print "Your pythoncurses module is old. Please upgrade to 1.4 or higher."
+       print "Alternative: Modify the script. Change all 6 occurences of curses.KEY_UP"
+       print "and similiar to lowercase."
+
+try : testAF = ABOOKFILE #test if ALIASFILE was configured in script
+except NameError:
+       try: ALIASFILE=os.environ["ABOOKFILE"] #test is environment MUTTALIASFILE was set
+       except KeyError:
+               print "Please specify ABOOKFILE at beginning of script \nor set environment variable ABOOKFILE"
+               print "Aborting ..."
+               sys.exit()
+
+
+
+###Thanks for the following go to Michael P. Reilly
+if not sys.stdin.isatty():  # is it not attached to a terminal?
+  file = sys.stdin.read()
+  sys.stdin = _dev_tty = open('/dev/tty', 'w+')
+  # close the file descriptor for stdin thru the posix module
+  os.close(0)
+  # now we duplicate the opened _dev_tty file at file descriptor 0 (fd0)
+  # really, dup creates the duplicate at the lowest numbered, closed file
+  # descriptor, but since we just closed fd0, we know we will dup to fd0
+  os.dup(_dev_tty.fileno())  # on UNIX, the fileno() method returns the
+                             # file object's file descriptor
+else:  # is a terminal
+       print "Please use as a pipe!"
+       print "Aborting..."
+       sys.exit()
+# now standard input points to the terminal again, at the C level, not just
+# at the Python level.
+
+
+print "Looking for mail adresses, this may take a while..."
+
+
+####  define functions
+
+
+class screenC:
+       "Class to create a simple to use menu using curses"
+       def __init__(self):
+               import curses, traceback
+               self.MAXSECT = 0
+               self.LSECT = 1
+               # Initialize curses
+               self.stdscr=curses.initscr()
+               # Turn off echoing of keys, and enter cbreak mode,
+               # where no buffering is performed on keyboard input
+               curses.noecho() 
+               curses.cbreak()
+
+               # In keypad mode, escape sequences for special keys
+               # (like the cursor keys) will be interpreted and
+               # a special value like curses.KEY_LEFT will be returned
+               self.stdscr.keypad(1)           
+       
+       def titel(self,TITEL="Title  - test",HELP="Use up and down arrows + Return"):   
+               "Draws Title and Instructions"
+               self.stdscr.addstr(0,0,TITEL,curses.A_UNDERLINE)                                # Title + Help
+               self.stdscr.addstr(self.Y -2 ,0,HELP,curses.A_REVERSE)
+
+       def refresh(self):
+               self.stdscr.refresh()
+
+       def size(self):
+               "Returns screen size and cursor position"
+               #Y, X = 0, 0
+               self.Y, self.X = self.stdscr.getmaxyx()
+               #self.y, self.x = 0, 0
+               self.y, self.x = self.stdscr.getyx()
+               #print Y, X
+               return self.Y, self.X, self.y, self.x
+               
+
+       def showlist(self,LISTE,LSECT=1):
+               "Analyzes list, calculates screen, draws current part of list on screen "
+               s = self.Y -3                                                           #space on screen
+               self.MAXSECT=1
+               while len(LISTE) > self.MAXSECT * s :           # how many times do we need the screen?
+                       self.MAXSECT = self.MAXSECT +1
+                       
+               if self.LSECT > self.MAXSECT:                           #check for end of list
+                       self.LSECT = LSECT -1
+               
+               if self.LSECT <=        0:                                              # 
+                       self.LSECT =1           
+               
+               if len(LISTE) <= s:
+                       self.LISTPART=LISTE
+               
+               else :
+                       self.LISTPART=LISTE[s * ( self.LSECT -1 ) : s * self.LSECT ]    # part of the List is shown
+               
+               self.stdscr.addstr(self.Y -2, self.X -len(`self.LSECT`+`self.MAXSECT`) -5, "(" + `self.LSECT` + "/" + `self.MAXSECT` + ")")
+               #if len(LISTE) > self.Y - 3:
+               #       return 1
+               for i in range (1, self.Y -2):                  # clear screen between title and help text
+                       self.stdscr.move(i , 0)
+                       self.stdscr.clrtoeol()
+               for i in range (0,len(self.LISTPART)):          # print out current part of list
+                       Item = self.LISTPART[i]
+                       self.stdscr.addstr(i +1, 0, Item[:self.X])
+       
+       def getresult(self,HOEHE):
+               "Get Result from cursor position"
+               RESULT= self.LISTPART[(HOEHE -1)]
+               return RESULT
+       
+       def showresult(self, HOEHE, DICT={}):
+               "Look up result to show in dictionary if provided, return list member otherwise"
+               if DICT=={}:
+                       return self.getresult(HOEHE)
+               else :
+                       return string.join(DICT[self.getresult(HOEHE)], " || ")
+               
+
+       
+       def menucall(self, LISTE, DICT={}, TITEL="",HELP="Use up and down arrows, Return to select"):
+               "Takes a list and offers a menu where you can choose one item, optionally, look up result in dictionary if provided"
+               REFY=1
+               self.__init__()
+               self.size()
+               self.titel(TITEL,HELP)
+               self.showlist(LISTE)
+               self.refresh()
+               self.stdscr.move(1,0)
+               while 1:                                                                        # read Key events 
+                       c = self.stdscr.getch()
+                       self.size()
+                       
+                       #if c == curses.KEY_LEFT and self.x  > 0:
+                       #       self.stdscr.move(self.y, self.x -1); REFY = 1 # REFY == refresh: yes
+                       
+                       #if c == curses.KEY_RIGHT               and self.x < self.X -1:
+                       #       #if x < 4 and LENGTH - ZAHLY > y - 1: 
+                       #       self.stdscr.move(self.y, self.x + 1); REFY = 1
+                       
+                       if c == curses.KEY_UP or c == 107: #up arrow or k
+                               if self.y > 1:
+                                       self.stdscr.move(self.y -1, self.x); REFY = 1
+                               else :
+                                       self.LSECT=self.LSECT-1
+                                       self.showlist(LISTE,self.LSECT)
+                                       self.stdscr.move(len(self.LISTPART), 0)
+                                       REFY = 1
+                               
+                       if c == curses.KEY_DOWN or c == 106: #down arrow or j
+                               
+                               if self.y < len(self.LISTPART) :        
+                                       self.stdscr.move(self.y +1, self.x); REFY = 1
+
+                               else :
+                                       self.LSECT=self.LSECT+1
+                                       self.showlist(LISTE,self.LSECT)
+                                       self.stdscr.move(1,0)
+                                       REFY = 1
+                       
+                       if c == curses.KEY_PPAGE:
+                               self.LSECT=self.LSECT-1
+                               self.showlist(LISTE,self.LSECT)
+                               self.stdscr.move(1, 0)
+                               REFY = 1
+
+                       if c == curses.KEY_NPAGE:
+                               self.LSECT=self.LSECT+1
+                               self.showlist(LISTE,self.LSECT)
+                               self.stdscr.move(1,0)
+                               REFY = 1
+
+                       if c == curses.KEY_END:
+                               self.LSECT=self.MAXSECT
+                               self.showlist(LISTE,self.LSECT)
+                               self.stdscr.move(1,0)
+                               REFY = 1
+                       
+                       if c == curses.KEY_HOME:
+                               self.LSECT=1
+                               self.showlist(LISTE,self.LSECT)
+                               self.stdscr.move(1,0)
+                               REFY = 1
+
+
+                       if c == 10 :                            # \n (new line)
+                               ERG = self.getresult(self.y )
+                               self.end()
+                               return ERG
+                       
+                       if c == 113 or c == 81:                 # "q or Q"
+                               self.printoutnwait("Aborted by user!")
+                               self.end()
+                               sys.exit()
+                               return 0
+                               
+                       if REFY == 1:
+                               REFY = 0
+                               self.size()
+                               self.stdscr.move(self.Y -1, 0)
+                               self.stdscr.clrtoeol()
+                               self.stdscr.addstr(self.Y -1, 0, self.showresult(self.y,DICT)[:self.X -1 ], curses.A_BOLD)
+                               self.stdscr.move(self.y, self.x)
+                               self.refresh()
+
+       def end(self):
+               "Return terminal"
+               # In the event of an error, restore the terminal
+               # to a sane state.
+               self.Y, self.X, self.y, self.x = 0, 0, 0, 0
+               self.LISTPART=[]
+               self.stdscr.keypad(0)
+               curses.echo()
+               curses.nocbreak()
+               curses.endwin()
+               #traceback.print_exc()
+
+       def input(self, promptstr):
+               "raw_input equivalent in curses, asks for  Input and returns it"
+               self.size()
+               curses.echo()
+               self.stdscr.move(0,0)
+               self.stdscr.clear()
+               self.stdscr.addstr(promptstr)
+               self.refresh()
+               INPUT=self.stdscr.getstr()
+               curses.noecho()
+               return INPUT
+       
+                                       
+       def printoutnwait(self, promptstr):
+               "Print out Text, wait for key"
+               curses.noecho()
+               self.stdscr.move(0,0)
+               self.stdscr.clear()
+# The new Mutt client pauses after running the script already.  No reason
+# to pause twice.  -Josh
+#              self.stdscr.addstr(promptstr+"\n\n(press key)")
+#              self.refresh()
+#              c = self.stdscr.getch()# read Key events 
+               
+
+
+def listrex (str, rgx): # Return a list of all regexes matched in string
+       "Search string for all occurences of regex and return a list of them."
+       result = []
+       start = 0 # set counter to zero
+       ende =len (str) #set end position
+       suchadress = re.compile(rgx,re.LOCALE)#compile regular expression, with LOCALE
+       while 1:
+               einzelerg = suchadress.search(str, start,ende) #create Match Object einzelerg
+               if einzelerg == None:#until none is found
+                       break
+               result.append(einzelerg.group()) #add to result
+               start = einzelerg.end()
+       return result
+
+def strrex (str): # Return first occurence of regular exp  as string
+       "Search string for first occurence of regular expression and return it"
+       muster = re.compile(r"<?[\w\b.ßüöä-]+\@[\w.-]+>?", re.LOCALE)   #compile re
+       matobj = muster.search(str)             #get Match Objekt from string 
+       if muster.search(str) == None:          #if none found
+               return ""
+       return matobj.group()                   #return string 
+
+def stripempty (str):#Looks for all empty charcters and replaces them with a space
+       "Looks for all empty charcters and replaces them with a space,kills trailing"
+       p = re.compile( "\s+")          #shorten
+       shrt = p.sub(" ", str)
+       q = re.compile("^\s+|\s+$")     #strip
+       strp = q.sub("", shrt)
+       return strp
+
+def getmailadressfromstring(str):
+       "Takes str and gets the first word containing @ == mail adress"
+       StringSplit=string.split(str)
+       for i in range(len(StringSplit)):
+               if "@" in StringSplit[i]:
+                       return StringSplit[i]
+       return None
+
+### main program
+
+OCCLIST = listrex(file, '"?[\s\w\ö\ä\ü\-\ß\_.]*"?\s*<?[\w.-]+\@[\w.-]+>?')#get list, RE gets all Email adresses + prepending words
+
+if OCCLIST:
+       print len(OCCLIST),"possible adresses found!." 
+else: 
+       print"ERROR, no mails found"
+       sys.exit()
+
+
+for i in range(len(OCCLIST)):                  #strip all whitespaces + trailing from each list member
+       OCCLIST[i] = string.strip(OCCLIST [i])
+
+
+OCCDIC={}                                              # Dictionary created to avoid duplicates
+for i in range(len(OCCLIST)):                  # iterate over 
+       d = OCCLIST[i]
+       Mail = getmailadressfromstring(OCCLIST[i])
+                       #strrex(OCCLIST[i])                     #Mailadresse
+       Schnitt = - len(Mail)                           #cut off mail adress
+       Mail = string.replace(Mail, "<", "")#remove <>
+       Mail = string.replace(Mail, ">", "")
+       Name = string.replace (stripempty (d[:Schnitt]), '"', '')               #leaves name
+       if not OCCDIC.get(Mail):                        # if new Emailadress
+               Liste = []                                              # create list for names
+               Liste.append(Name)                              # append name 
+               OCCDIC[Mail] = Liste                    # assign list to adress
+       else :  
+               Liste = OCCDIC[Mail]                    # otherwise get list
+               Liste.append(Name)                              # append name to list of names
+               OCCDIC[Mail] =  Liste                   # and assign
+
+
+KEYS = OCCDIC.keys()                           #iterate over dictionary, sort names 
+                                                                       #KEYS are all the adresses
+
+for z in range( len(KEYS) ): 
+       NAMLIST = OCCDIC[KEYS[z]]               # Get list of possible names
+       d = {}                                                  # sort out duplicates and 
+                                                                       # remove bad names + empty strings from adresses
+       for x in NAMLIST: 
+               if x in ["", "<"]: continue
+               d[x]=x
+       NAMLIST = d.values()
+       NAMLIST.sort()                                  # sort namelist alphabetically
+       print z, KEYS[z], "had possible names:", NAMLIST # Debugging output
+       OCCDIC[KEYS[z]] = NAMLIST               # 
+
+print "\n"
+
+###sorting
+
+def Comparelength(x, y):
+       "Compare number of names in OCCDIC, if equal sort alphabetically."
+       if len(OCCDIC[y]) == len(OCCDIC[x]):
+               return cmp(x, y)
+       if len(OCCDIC[y]) < len(OCCDIC[x]):
+               return -1
+       else:
+               return 1        
+
+KEYS.sort(Comparelength)                                       # Keys sort
+
+###menu
+
+ScreenObject=screenC()                 # initialize curses menu
+try:
+       ZIELADRESS = ScreenObject.menucall(KEYS, OCCDIC, "Choose adress to alias")
+       if OCCDIC[ZIELADRESS]:
+               LISTNAM=["***ENTER own NAME"]           #add option to edit name
+               LISTNAM= LISTNAM + OCCDIC[ZIELADRESS]
+               ZIELNAME   = ScreenObject.menucall(LISTNAM, {}, ZIELADRESS + " has which of the possible names?")
+               # empty Dictionary {} means show list member itself, not looked up result
+       else : ZIELNAME=""
+except:
+       T=ScreenObject.size()
+       ScreenObject.end()
+#      traceback.print_exc() # Uncomment for curses debugging info
+#      print T
+       sys.exit()
+
+### enter new names/aliases
+
+if  ZIELNAME == "***ENTER own NAME" or ZIELNAME == "":
+       ZIELNAME = ScreenObject.input(`ZIELADRESS` + " = " + `OCCDIC[ZIELADRESS]` + "\n" + `ZIELADRESS` + " gets which name? ")
+
+if ZIELNAME == "":
+       ZIELNAME = "No name"
+
+WRITEALIAS = "\n[]\nname=" + ZIELNAME + "\nemail=" + ZIELADRESS + "\n\n"
+
+f = open(ABOOKFILE, "a")
+f.write(WRITEALIAS)
+f.close()
+
+ScreenObject.printoutnwait("Item was added to "+  ABOOKFILE + "\nProgam terminated")
+ScreenObject.end()
+
diff --git a/contrib/vcard2abook.pl b/contrib/vcard2abook.pl
new file mode 100755 (executable)
index 0000000..296a18c
--- /dev/null
@@ -0,0 +1,91 @@
+#!/usr/bin/perl -w
+my $timestamp= "Time-stamp: \"vcard2abook.pl was last updated on Sun, 17 Dec 2000 10:34am\"";
+
+#==============================================================================*
+#   vcard2abook.pl by jeff covey <jeff.covey@pobox.com>                        *
+#                                                                              *
+#   this script has two main features:                                         *
+#                                                                              *
+#   1. it converts a file containing addressbook entries in vcard format to    *
+#      one containing entries in abook format.                                 *
+#   2. it almost has more comments than code.                                  *
+#                                                                              *
+#   This program is free software; you can redistribute it and/or modify       *
+#   it under the terms of the GNU General Public License as published by       *
+#   the Free Software Foundation; either version 2 of the License, or          *
+#   (at your option) any later version.                                        *
+#                                                                              *
+#   This program is distributed in the hope that it will be useful,            *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+#   GNU General Public License for more details.                               *
+#                                                                              *
+#   You should have received a copy of the GNU General Public License          *
+#   along with this program; if not, write to the Free Software                *
+#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                  *
+#==============================================================================*
+
+use strict;
+
+($#ARGV >= 1) or die
+  "usage: vcard2abook.pl <vcard input file> <abook output file>\noutput file will be overwritten!\n";
+
+my $vcards="$ARGV[0]";
+my $abook ="$ARGV[1]";
+my $key;
+
+my %conversions = (
+                  "FN"         => "name=",
+                  "NICKNAME"   => "nick=",
+                  "EMAIL"      => "email=",
+                  "ORG"        => "notes=",
+                  "NOTE"       => "notes=",
+                  "URL"        => "url=",
+                  
+                  "TEL;HOME"   => "phone=",
+                  "TEL;PREF"   => "phone=",
+                  "TEL;VOICE"  => "phone=",
+                  "TEL;MSG"    => "phone=",
+                  "TEL;VIDEO"  => "phone=",
+                  "TEL;MODEM"  => "phone=",
+                  "TEL;ISDN"   => "phone=",
+                  "TEL;WORK"   => "workphone=",
+                  "TEL;CELL"   => "mobile=",
+                  "TEL;PAGER"  => "mobile=",
+                  "TEL;CAR"    => "mobile=",
+                  "TEL;FAX"    => "fax=",
+                  );
+
+open (VCARDS,"$vcards") or quit("couldn't open $vcards");
+open (ABOOK,">$abook")  or quit("couldn't open $abook for writing");
+
+while (<VCARDS>) {
+  if    (/^\s*$/)         { }
+  elsif (/^BEGIN:VCARD/i) { print ABOOK "[]\n"; }
+  elsif (/^END:VCARD/i)   { print ABOOK   "\n"; }
+  else {
+    chomp; my @sections=split /:/, $_, 2;
+    if ($sections[0] =~ /^ADR/i) {
+      my @fields=split /;/, $sections[1];
+      if ($fields[2]) {print ABOOK "address=$fields[2]\n";}
+      if ($fields[3]) {print ABOOK "city=$fields[3]\n";   }
+      if ($fields[4]) {print ABOOK "state=$fields[4]\n";  }
+      if ($fields[5]) {print ABOOK "zip=$fields[5]\n";    }
+      if ($fields[6]) {print ABOOK "country=$fields[6]\n";}
+    }
+    else {
+      foreach $key (keys %conversions) {
+       if ($sections[0] =~ /^$key/i) {
+         print ABOOK "$conversions{$key}$sections[1]\n";
+       }
+      }
+    }
+  }
+}
+
+close (VCARDS) or quit("couldn't close $vcards");
+close (ABOOK)  or quit("couldn't close $abook");
+
+sub quit {
+  print "whoops!  $_[0]:\n $!\n"; die;
+}
diff --git a/contrib/whitelist/README b/contrib/whitelist/README
new file mode 100644 (file)
index 0000000..7ab473a
--- /dev/null
@@ -0,0 +1,41 @@
+
+0.4.13 NOTE:
+There's no need to patch abook now. -JH
+
+
+Taken from message sent by "R. Shohn Trojacek" <snazzle@galvani.tamu.edu>
+
+--
+
+hello,
+
+Here are some patches and things for abook 0.4.8
+
+[patching instructions removed (not needed anymore) -JH]
+
+anyway it allows the use of a "whitelist" which is to
+say people that are in the address book show up with
+a higher precedence by changing the mail to a different color.
+
+this is accomplished using a simple procmail filter
+and a couple of mutt commands.
+
+just
+
+INCLUDERC=/path/whitelist.rc
+
+inside of your .procmailrc
+
+
+and then add
+
+source /path/mutt.whitelist
+to the top of your muttrc
+
+
+
+
+abook2whitelist.sh
+
+--
+
diff --git a/contrib/whitelist/abook2whitelist.sh b/contrib/whitelist/abook2whitelist.sh
new file mode 100755 (executable)
index 0000000..21e92de
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+abook --mutt-query all | tail +2 | cut -f 1 > ~/.procmail/white.lst
+
diff --git a/contrib/whitelist/mutt.whitelist b/contrib/whitelist/mutt.whitelist
new file mode 100644 (file)
index 0000000..44eed7a
--- /dev/null
@@ -0,0 +1,2 @@
+color index white black  '! ~p'
+color index green  black  '~h whitelist'
diff --git a/contrib/whitelist/patch.orig.obsolete b/contrib/whitelist/patch.orig.obsolete
new file mode 100644 (file)
index 0000000..8cc1415
--- /dev/null
@@ -0,0 +1,61 @@
+54a55,56
+> static void             procmail_query(char *str);
+> static void             procmail_print_email(int item);
+498a501,503
+>              if( !strcmp(argv[i], "--procmail-query") )
+>                      procmail_query(argv[i + 1]);
+>              else
+561a567,583
+> 
+> static void
+> procmail_print_email(int item)
+> {
+>      char emails[MAX_EMAILS][MAX_EMAIL_LEN];
+> 
+>      split_emailstr(item, emails);
+>      
+>      if( options_get_int("mutt", "return_all_emails") ) {
+>              int i;
+>              for(i=0; i<MAX_EMAILS; i++)
+>                      if( *emails[i] )
+>                              printf("%s\n", emails[i]);
+>      } else
+>              printf("%s\n", emails[0]);
+> }
+> 
+571c593
+<              printf("All items\n");
+---
+>              /*printf("All items\n");*/
+580a603,633
+>                              j++;
+>                      }
+>                      free(tmp);
+>              }
+>              if( !j )
+>                      printf("Not found\n");
+>      }
+> 
+>      quit_mutt_query();
+>      exit(0);
+> }
+> 
+> static void
+> procmail_query(char *str)
+> {
+>      int i, j;
+>      char *tmp;
+>      
+>      init_mutt_query();
+> 
+>      if( str == NULL || !strcasecmp(str, "all") ) {
+>              /*printf("All items\n");*/
+>              for(i = 0; i < items; i++)
+>                      procmail_print_email(i);
+>      } else {
+>              for(i = 0, j = 0 ; i < items; i++) {
+>                      tmp = strdup(database[i][NAME]);
+>                      if( strstr( strupper(tmp), strupper(str) ) != NULL ) {
+>                              if( !j )
+>                                      putchar('\n');
+>                              procmail_print_email(i);
diff --git a/contrib/whitelist/whitelist.rc b/contrib/whitelist/whitelist.rc
new file mode 100755 (executable)
index 0000000..fc9e51d
--- /dev/null
@@ -0,0 +1,9 @@
+# Test if the email's sender is in the whitelist
+ :0
+ * ? formail -x"From" -x"From:" -x"Sender:" \
+     -x"Reply-To:" -x"Return-Path:" -x"To:" \
+         | egrep -is -f ~/.procmail/white.lst
+{
+ :0 fwh
+      | formail -a"X-Match: whitelist"
+}
diff --git a/database.c b/database.c
new file mode 100644 (file)
index 0000000..65d5082
--- /dev/null
@@ -0,0 +1,480 @@
+
+/*
+ * $Id: database.c,v 1.14 2001/11/20 19:35:29 jheinonen Exp $
+ *
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include "abook.h"
+#include "database.h"
+#include "list.h"
+#include "misc.h"
+#include "options.h"
+#include "filter.h"
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+
+static void    free_item(int i);
+
+
+list_item *database = NULL;
+
+int items = 0;
+
+#define INITIAL_LIST_CAPACITY  30
+
+int list_capacity = 0;
+
+extern int first_list_item;
+extern int curitem;
+extern char *selected;
+
+extern char *datafile;
+extern char *rcfile;
+
+/*
+ * field definitions
+ */
+
+#include "edit.h"
+
+/*
+ * notes about adding fields:
+ *     - do not change any fields in TAB_CONTACT
+ *     - do not add fields to contact tab
+ *     - 6 fields per tab is maximum
+ *     - reorganize the field numbers in database.h
+ */
+
+struct abook_field abook_fields[ITEM_FIELDS] = {
+       {"Name",        "name",         TAB_CONTACT},/* NAME */
+       {"E-mails",     "email",        TAB_CONTACT},/* EMAIL */
+       {"Address",     "address",      TAB_ADDRESS},/* ADDRESS */
+       {"Address2",    "address2",     TAB_ADDRESS},/* ADDRESS2 */   
+       {"City",        "city",         TAB_ADDRESS},/* CITY */
+       {"State/Province","state",      TAB_ADDRESS},/* STATE */
+       {"ZIP/Postal Code","zip",       TAB_ADDRESS},/* ZIP */
+       {"Country",     "country",      TAB_ADDRESS},/* COUNTRY */
+       {"Home Phone",  "phone",        TAB_PHONE},/* PHONE */
+       {"Work Phone",  "workphone",    TAB_PHONE},/* WORKPHONE */
+       {"Fax",         "fax",          TAB_PHONE},/* FAX */
+       {"Mobile",      "mobile",       TAB_PHONE},/* MOBILEPHONE */
+       {"Nickname/Alias", "nick",      TAB_OTHER},/* NICK */
+       {"URL",         "url",          TAB_OTHER},/* URL */
+       {"Notes",       "notes",        TAB_OTHER},/* NOTES */
+};
+
+
+int
+parse_database(FILE *in)
+{
+        char *line = NULL;
+       char *tmp;
+       int sec=0, i;
+       list_item item;
+
+       memset(&item, 0, sizeof(item));
+       
+       for(;;) {
+               line = getaline(in);
+               if( feof(in) ) {
+                       if( item[NAME] && sec )
+                               add_item2database(item);
+                       else
+                               free_list_item(item);
+                       break;
+               }
+
+               if( !*line || *line == '\n' || *line == '#' ) {
+                       free(line);
+                       continue;
+               } else if( *line == '[' ) {
+                       if( item[NAME] && sec )
+                               add_item2database(item);
+                       else
+                               free_list_item(item);
+                       memset(&item, 0, sizeof(item));
+                       sec = 1;
+                       if ( !(tmp = strchr(line, ']')))
+                               sec = 0; /*incorrect section lines are skipped*/
+               } else if((tmp = strchr(line, '=') ) && sec ) {
+                       *tmp++ = '\0';
+                       for(i=0; i<ITEM_FIELDS; i++)
+                               if( !strcmp(abook_fields[i].key, line) ) {
+                                       item[i] = strdup(tmp);
+                                       goto next;
+                               }
+               }
+next:
+               free(line);
+       }
+
+       free(line);
+       return 0;
+}
+
+               
+
+int
+load_database(char *filename)
+{
+       FILE *in;
+
+       if( database != NULL )
+               close_database();
+
+       if ( (in = abook_fopen(filename, "r")) == NULL )
+               return -1;
+       
+       parse_database(in);
+
+       if ( items == 0 )
+               return 2;
+
+       return 0;
+}
+
+int
+write_database(FILE *out, struct db_enumerator e)
+{
+       int j;
+       int i = 0;
+
+       fprintf(out,
+               "# abook addressbook file\n\n"
+               "[format]\n"
+               "program=" PACKAGE "\n"
+               "version=" VERSION "\n"
+               "\n\n"
+       );
+
+       db_enumerate_items(e) {
+               fprintf(out, "[%d]\n", i);
+               for(j = 0; j < ITEM_FIELDS; j++) {
+                       if( database[e.item][j] != NULL &&
+                                       *database[e.item][j] )
+                               fprintf(out, "%s=%s\n",
+                                       abook_fields[j].key,
+                                       database[e.item][j]
+                                       );
+               }
+               fputc('\n', out);
+               i++;
+       }
+
+       return 0;
+}
+
+int
+save_database()
+{
+       FILE *out;
+       struct db_enumerator e = init_db_enumerator(ENUM_ALL);
+
+       if( (out = abook_fopen(datafile, "w")) == NULL )
+               return -1;
+
+       if( list_is_empty() ) {
+               fclose(out);
+               unlink(datafile);
+               return 1;
+       }
+
+       
+       write_database(out, e);
+       
+       fclose(out);
+       
+       return 0;
+}
+
+static void
+free_item(int item)
+{
+       free_list_item(database[item]);
+}
+
+void
+free_list_item(list_item item)
+{
+       int i;
+
+       for(i=0; i<ITEM_FIELDS; i++)
+               my_free(item[i]);
+}
+
+void
+close_database()
+{
+       int i;
+       
+       for(i=0; i < items; i++)
+               free_item(i);
+
+       free(database);
+       free(selected);
+
+       database = NULL;
+       selected = NULL;
+
+       items = 0;
+       first_list_item = curitem = -1;
+       list_capacity = 0;
+}
+
+#define _MAX_FIELD_LEN(X)      (X == EMAIL ? MAX_EMAILSTR_LEN:MAX_FIELD_LEN)
+
+static void
+validate_item(list_item item)
+{
+       int i;
+       char *tmp;
+       
+       if(item[EMAIL] == NULL)
+               item[EMAIL] = strdup("");
+
+       for(i=0; i<ITEM_FIELDS; i++)
+               if( item[i] && (strlen(item[i]) > _MAX_FIELD_LEN(i) ) ) {
+                       tmp = item[i];
+                       item[i][_MAX_FIELD_LEN(i)-1] = 0;
+                       item[i] = strdup(item[i]);
+                       free(tmp);
+               }
+}
+
+
+static void
+adjust_list_capacity()
+{
+       if(list_capacity < 1)
+               list_capacity = INITIAL_LIST_CAPACITY;
+       else if(items >= list_capacity)
+               list_capacity *= 2;
+       else if(list_capacity / 2 > items)
+               list_capacity /= 2;
+       else
+               return;
+
+       database = abook_realloc(database,
+                       sizeof(list_item) * list_capacity);
+       selected = abook_realloc(selected, list_capacity);
+}
+
+int
+add_item2database(list_item item)
+{
+       if( item[NAME] == NULL || ! *item[NAME] ) {
+               free_list_item(item);
+               return 1;
+       }
+
+       if( ++items > list_capacity)
+               adjust_list_capacity();
+
+       validate_item(item);
+
+       selected[LAST_ITEM] = 0;
+       itemcpy(database[LAST_ITEM], item);
+
+       return 0;
+}
+
+void
+remove_selected_items()
+{
+       int i, j;
+
+       if( list_is_empty() )
+               return;
+
+       if( ! selected_items() )
+               selected[ curitem ] = 1;
+       
+       for( j = LAST_ITEM; j >= 0; j-- ) {
+               if( selected[j] ) {
+                       free_item(j); /* added for .4 data_s_ */
+                       for( i = j; i < LAST_ITEM; i++ ) {
+                               itemcpy(database[ i ], database[ i + 1 ]);
+                               selected[ i ] = selected[ i + 1 ];
+                       }
+                       items--;        
+               }
+       }
+
+       if( curitem > LAST_ITEM && items > 0 )
+               curitem = LAST_ITEM;
+
+
+       adjust_list_capacity();
+
+       select_none();
+}
+
+char *
+get_surname(char *s)
+{
+       int i, a;
+       int len = strlen(s);
+       char *name = strdup(s);
+
+       for( a = 0, i = len - 1; i >= 0; i--, a++ ) {
+               name[a] = s[i];
+               if(name[a] == ' ')
+                       break;
+       }
+
+       name[ a ] = 0;
+
+       revstr(name);
+
+       return name;
+}
+
+static int
+surnamecmp(const void *i1, const void *i2)
+{
+       int ret;
+       list_item a,b;
+       char *s1, *s2;
+
+       itemcpy(a, i1);
+       itemcpy(b, i2);
+
+       s1 = get_surname(a[NAME]);
+       s2 = get_surname(b[NAME]);
+
+       if( !(ret = safe_strcoll(s1, s2)) )
+               ret = safe_strcoll(a[NAME], b[NAME]);
+
+       free(s1);
+       free(s2);
+
+       return ret;
+}
+
+static int
+namecmp(const void *i1, const void *i2)
+{
+       list_item a, b;
+
+       itemcpy(a, i1);
+       itemcpy(b, i2);
+       
+       return safe_strcoll( a[NAME], b[NAME] );
+}
+
+void
+sort_database()
+{
+       select_none();
+       
+       qsort((void *)database, items, sizeof(list_item), namecmp);
+
+       refresh_screen();
+}
+
+void
+sort_surname()
+{
+       select_none();
+
+       qsort((void *)database, items, sizeof(list_item), surnamecmp);
+
+       refresh_screen();
+}
+
+int
+find_item(char *str, int start, int search_fields[])
+{
+       int i;
+       char *findstr = NULL;
+       char *tmp = NULL;
+       int ret = -1; /* not found */
+       struct db_enumerator e = init_db_enumerator(ENUM_ALL);
+
+       if(list_is_empty() || !is_valid_item(start))
+               return -2; /* error */
+
+       findstr = strdup(str);
+       findstr = strupper(findstr);
+
+       e.item = start - 1; /* must be "real start" - 1 */
+       db_enumerate_items(e) {
+               for( i = 0; search_fields[i] >= 0; i++ ) {
+                       tmp = safe_strdup(database[e.item][search_fields[i]]);
+                       if( tmp && strstr(strupper(tmp), findstr) ) {
+                               ret = e.item;
+                               goto out;
+                       }
+                       my_free(tmp);
+               }
+       }
+
+out:
+       free(findstr);
+       free(tmp);
+       return ret;
+}
+
+
+int
+is_selected(int item)
+{
+       return selected[item];
+}
+
+int
+is_valid_item(int item)
+{
+       return item <= LAST_ITEM && item >= 0;
+}
+
+int
+real_db_enumerate_items(struct db_enumerator e)
+{
+       int item = max(0, e.item + 1);
+       int i;
+       
+       switch(e.mode) {
+#ifdef DEBUG
+               case ENUM_ALL:
+                       break;
+#endif
+               case ENUM_SELECTED:
+                       for(i = item; i < items; i++) {
+                               if(is_selected(i)) {
+                                       item = i;
+                                       goto out;
+                               }
+                       }
+                       return -1;
+#ifdef DEBUG
+               default:
+                       fprintf(stderr, "real_db_enumerate_items() "
+                                       "BUG: unknown db_enumerator mode: %d\n",
+                                       e.mode);
+                       break;
+#endif
+       }
+out:
+       return (item > LAST_ITEM || item < 0) ? -1 : item;
+}
+
+struct db_enumerator
+init_db_enumerator(int mode)
+{
+       struct db_enumerator new;
+
+       new.item = -1; /* important - means "start from beginning" */
+       new.mode = mode;
+
+       return new;
+}
diff --git a/database.h b/database.h
new file mode 100644 (file)
index 0000000..142d1b0
--- /dev/null
@@ -0,0 +1,92 @@
+#ifndef _DATABASE_H
+#define _DATABASE_H
+
+
+#define MAX_EMAILS             4
+#define MAX_EMAIL_LEN          80
+#define MAX_EMAILSTR_LEN       (MAX_EMAILS*MAX_EMAIL_LEN + MAX_EMAILS + 1)
+#define MAX_FIELD_LEN          81
+
+enum {
+       NAME,
+       EMAIL,
+       ADDRESS,
+        ADDRESS2,
+       CITY,
+       STATE,
+       ZIP,
+       COUNTRY,
+       PHONE,
+       WORKPHONE,
+       FAX,
+       MOBILEPHONE,
+       NICK,
+       URL,
+       NOTES,
+};
+
+#define LAST_FIELD             NOTES
+
+#define ITEM_FIELDS            (LAST_FIELD+1)
+
+typedef char * list_item[ITEM_FIELDS];
+
+struct abook_field {
+       char *name;
+       char *key;
+       int tab;
+};
+
+enum {
+       ENUM_ALL,
+       ENUM_SELECTED
+};
+
+struct db_enumerator {
+       int item;
+       int mode; /* warning: read only */
+};
+
+int            parse_database(FILE *in);
+int            write_database(FILE *out, struct db_enumerator e);
+int            load_database(char *filename);
+int            save_database();
+void           close_database();
+int            add_item2database(list_item item);
+void           free_list_item(list_item item);
+void           remove_selected_items();
+void           sort_surname();
+void           sort_database();
+char           *get_surname(char *s);
+int            find_item(char *str, int start, int search_fields[]);
+int            is_selected(int item);
+int            is_valid_item(int item);
+
+int            real_db_enumerate_items(struct db_enumerator e);
+struct db_enumerator   init_db_enumerator(int mode);
+
+#define LAST_ITEM      (items - 1)
+
+#define itemcpy(dest, src)     memmove(dest, src, sizeof(list_item))
+
+#define split_emailstr(item, emails) do {\
+       int _i,_j,_k,len; \
+       memset(&emails, 0, sizeof(emails) ); \
+       len = strlen(database[item][EMAIL]); \
+       for( _i=0,_j=0, _k=0; _i < len && _j < MAX_EMAILS; _i++ ) { \
+               if( database[item][EMAIL][_i] ==',' ) { \
+                       _j++; \
+                       _k = 0; \
+               } else \
+                       if( _k < MAX_EMAIL_LEN -1 ) \
+                               emails[_j][_k++] = database[item][EMAIL][_i]; \
+       } \
+} while(0)
+
+#define have_multiple_emails(item) \
+       strchr(database[item][EMAIL], ',')
+
+#define db_enumerate_items(e) \
+       while( -1 != (e.item = real_db_enumerate_items(e)))
+
+#endif
diff --git a/edit.c b/edit.c
new file mode 100644 (file)
index 0000000..7738c5c
--- /dev/null
+++ b/edit.c
@@ -0,0 +1,440 @@
+
+/*
+ * $Id: edit.c,v 1.18 2001/10/12 09:32:51 jheinonen Exp $
+ *
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include "abook_curses.h"
+#include "ui.h"
+#include "abook.h"
+#include "database.h"
+#include "list.h"
+#include "edit.h"
+#include "misc.h"
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+
+/*
+ * some extern variables
+ */
+
+extern struct abook_field abook_fields[];
+
+extern list_item *database;
+extern int curitem;
+extern int items;
+
+WINDOW *editw;
+
+static void
+editor_tab(int tab)
+{
+       int i;
+       char *tab_names[] = {
+               "/ CONTACT \\",
+               "/ ADDRESS \\",
+               "/  PHONE  \\",
+               "/  OTHER  \\"
+       };
+
+       mvwhline(editw, TABLINE+1, 0, UI_HLINE_CHAR, EDITW_COLS);
+
+       for(i=0; i < TABS; i++)
+               mvwaddstr(editw, TABLINE, 16 * i + 3, tab_names[i]);
+
+       mvwaddstr(editw, TABLINE+1, 16 * tab + 2, "/           \\");
+}
+
+void
+get_first_email(char *str, int item)
+{
+       char *tmp;
+
+       if(database[item][EMAIL] == NULL) {
+               *str = 0;
+               return;
+       }
+
+       strncpy(str, database[item][EMAIL], MAX_EMAIL_LEN);
+       if( (tmp = strchr(str, ',')) )
+               *tmp=0;
+       else
+               str[MAX_EMAIL_LEN-1] = 0;
+}
+
+static void
+roll_emails(int item)
+{
+       char tmp[MAX_EMAILSTR_LEN];
+       char *p;
+
+       strcpy(tmp, database[item][EMAIL]);
+
+       if( !(p = strchr(tmp, ',')) )
+               return;
+       else
+               *p=0;
+
+       strcpy(database[item][EMAIL], p+1);
+       strcat(database[item][EMAIL], ",");
+       strcat(database[item][EMAIL], tmp);     
+}
+
+static void
+init_editor()
+{
+       clear();
+       editw = newwin(EDITW_LINES, EDITW_COLS, EDITW_TOP, EDITW_X);
+
+       refresh_statusline();
+}
+
+/*
+ * we have to introduce edit_undo here
+ */
+static void edit_undo(int item, int mode);
+
+enum {
+       BACKUP_ITEM,
+       RESTORE_ITEM,
+       CLEAR_UNDO
+};
+
+
+static void
+close_editor()
+{
+       edit_undo(-1, CLEAR_UNDO);
+       delwin(editw);
+       refresh_screen();
+}
+
+static void
+print_editor_header(int item)
+{
+       char *header;
+       char email[MAX_EMAIL_LEN];
+       
+       if( (header = (char *)malloc(EDITW_COLS)) == NULL )
+               return;
+
+       get_first_email(email, item);
+       
+       if( *database[item][EMAIL] )
+               snprintf(header, EDITW_COLS, "%s <%s>",
+                               database[item][NAME],
+                               email);
+       else
+               snprintf(header, EDITW_COLS, "%s", database[item][NAME]);
+
+       mvwaddstr(editw, 0, (EDITW_COLS - strlen(header)) / 2,
+                       header);
+
+       free(header);
+}
+
+static void
+editor_print_data(int tab, int item)
+{
+       int i, j;
+       int y, x;
+
+       for(i = 0, j = 1; i < ITEM_FIELDS; i++) {
+               if(abook_fields[i].tab != tab)
+                       continue;
+
+               if(i==EMAIL) { /* special field */
+                       int k;
+                       char emails[MAX_EMAILS][MAX_EMAIL_LEN];
+                       split_emailstr(item, emails);
+                       getyx(editw, y, x);
+                       mvwaddstr(editw, y+1, FIELDS_START_X,
+                                       "E-mail addresses:");
+                       for(k = 0; k < MAX_EMAILS; k++) {
+                               getyx(editw, y, x);
+                               mvwprintw(editw, y+1, FIELDS_START_X,
+                               "%c -", '2' + k);
+                               mvwprintw(editw, y +1, TAB_COLON_POS,
+                                               ": %s", emails[k]);
+                       }
+                       continue;
+               }
+                               
+               if(j > 1) {
+                       getyx(editw, y, x); y++;
+               } else
+                       y = FIELDS_START_Y;
+
+               mvwprintw(editw, y, FIELDS_START_X, "%d - %s",
+                               j,
+                               abook_fields[i].name);
+               mvwaddch(editw, y, TAB_COLON_POS, ':');
+               mvwaddstr(editw, y, TAB_COLON_POS + 2,
+                               safe_str(database[item][i]));
+
+               j++;
+       }
+}
+
+/*
+ * function: change_field
+ * 
+ * parameters:
+ *  (char *msg)
+ *   message to display as a prompt
+ *  (char **field)
+ *   a pointer to pointer which will point a new string. if the latter
+ *   pointer != NULL it will be freed (if user doesn't cancel)
+ * 
+ * returns (int)
+ *  a nonzero value if user has cancelled and zero if user has typed a
+ *  valid string
+ */
+
+static int
+change_field(char *msg, char **field)
+{
+       char tmp[MAX_FIELD_LEN];
+       int max_len = MAX_FIELD_LEN;
+       int ret;
+       
+       if( !strncmp("E-mail", msg, 6) )
+               max_len = MAX_EMAIL_LEN;
+       
+       statusline_addstr(msg);
+       if( (ret = statusline_getnstr( tmp, max_len - 1, 0 ) ? 1:0 ) ) {
+               my_free(*field);
+               if( *tmp )
+                       *field = strdup(tmp);
+       }
+
+       clear_statusline();
+       refresh_statusline();
+
+       return !ret;
+}
+
+static void
+change_name_field(char **field)
+{
+       char *tmp;
+
+       tmp = strdup(*field);
+       change_field("Name: ", field);
+
+       if( *field == NULL || ! **field ) {
+               my_free(*field);
+               *field = strdup(tmp);
+       }
+
+       my_free(tmp);
+}
+
+static void
+fix_email_str(char *str)
+{
+       for(; *str; str++ )
+               *str = *str == ',' ? '_' : *str;
+}
+
+static void
+edit_emails(char c, int item)
+{
+       char *field = NULL;
+       char emails[MAX_EMAILS][MAX_EMAIL_LEN];
+       char tmp[MAX_EMAILSTR_LEN] = "";
+       int i, len;
+
+       split_emailstr(item, emails);
+
+       if(change_field("E-mail: ", &field)) {
+#ifdef DEBUG
+               fprintf(stderr, "change_field = TRUE\n");
+#endif
+               return; /* user cancelled ( C-g ) */
+       }
+       if(field) {
+               strncpy(emails[c - '2'], field, MAX_EMAIL_LEN);
+               fix_email_str(emails[c - '2']);
+       } else
+               *emails[c - '2'] = 0;
+       
+       my_free(database[item][EMAIL]);
+
+       for(i = 0; i < MAX_EMAILS; i++) {
+               if( *emails[i] ) {
+                       strcat(tmp, emails[i]);
+                       strcat(tmp, ",");
+               }
+       }
+
+       len = strlen(tmp);
+       if(tmp[len -1] == ',')
+               tmp[len-1] =0;
+
+       database[item][EMAIL] = strdup(tmp);
+}
+
+static int
+edit_field(int tab, char c, int item)
+{
+       int i, j;
+       int n = c - '1' + 1;
+       char *str;
+
+       if(n < 1 || n > MAX_TAB_FIELDS)
+               return 0;
+
+       edit_undo(item, BACKUP_ITEM);
+
+       if(tab == TAB_CONTACT) {
+               switch(c) {
+                       case '1': change_name_field(&database[item][NAME]);
+                                 break;
+                       case '2':
+                       case '3':
+                       case '4':
+                       case '5': edit_emails(c, item); break;
+                       default: return 0;
+               }
+               return 1;
+       }
+
+       for(i=0, j=0; i< ITEM_FIELDS; i++) {
+               if(abook_fields[i].tab == tab)
+                       j++;
+               if(j==n)
+                       break;
+       }
+
+       if(j!=n)
+               return 0;
+
+       str = mkstr("%s: ", abook_fields[i].name);
+       change_field(str, &database[item][i]);
+
+       free(str);
+
+       return 1;
+}
+
+static void
+edit_undo(int item, int mode)
+{
+       int i;
+       static list_item *backup = NULL;
+
+       switch(mode) {
+               case CLEAR_UNDO:
+                       if(backup) {
+                               free_list_item(backup[0]);
+                               my_free(backup);
+                       }
+                       break;
+               case BACKUP_ITEM:
+                       if(backup) {
+                               free_list_item(backup[0]);
+                               my_free(backup);
+                       }
+                       backup = abook_malloc(sizeof(list_item));
+                       for(i = 0; i < ITEM_FIELDS; i++)
+                               backup[0][i] = safe_strdup(database[item][i]);
+                       break;
+               case RESTORE_ITEM:
+                       if(backup) {
+                               free_list_item(database[item]);
+                               itemcpy(database[item], backup[0]);
+                               my_free(backup);
+                       }
+                       break;
+       }
+}
+
+static int
+edit_loop(int item)
+{
+       static int tab = 0; /* first tab */
+       int c;
+       
+       werase(editw);
+       headerline(EDITOR_HELPLINE);
+       refresh_statusline();
+       print_editor_header(item);
+       editor_tab(tab);
+       editor_print_data(tab, item);
+       wmove(editw, EDITW_LINES - 1, EDITW_COLS - 1);
+
+       refresh();
+       wrefresh(editw);
+
+       switch( (c = getch()) ) {
+               case 'c': tab = TAB_CONTACT; break;
+               case 'a': tab = TAB_ADDRESS; break;
+               case 'p': tab = TAB_PHONE; break;
+               case 'o': tab = TAB_OTHER; break;
+               case KEY_LEFT: tab = tab == 0 ? MAX_TAB : tab - 1;
+                              break;
+               case KEY_RIGHT: tab = tab == MAX_TAB ? 0 : tab + 1;
+                               break;
+               case '<':
+               case 'k': if(is_valid_item(item-1)) item--; break;
+               case '>':
+               case 'j': if(is_valid_item(item+1)) item++; break;
+               case 'r': roll_emails(item); break;
+               case '?': display_help(HELP_EDITOR); break;
+               case 'u': edit_undo(item, RESTORE_ITEM); break;
+               case 'm': launch_mutt(item); clearok(stdscr, 1); break;
+               case 'v': launch_wwwbrowser(item); clearok(stdscr, 1); break;
+               case 12 : clearok(stdscr, 1); break; /* ^L (refresh screen) */
+               default:  return edit_field(tab, c, item) ? item : -1;
+       }
+
+       return item;
+}
+
+void
+edit_item(int item)
+{
+       if( item < 0 ) {
+               if( curitem < 0 )
+                       return;
+               else
+                       item = curitem;
+       }
+
+       init_editor();
+
+       while( (item = edit_loop(item)) >= 0 )
+               curitem = item; /* hmm, this is not very clean way to go */
+
+       close_editor();
+}
+
+void
+add_item()
+{
+       char *field = NULL;
+       list_item item;
+
+       change_field("Name: ", &field);
+
+       if( field == NULL )
+               return;
+
+       memset(item, 0, sizeof(item));
+
+       item[NAME] = field;
+
+       add_item2database(item);
+
+       curitem = LAST_ITEM;
+
+       edit_item(LAST_ITEM);
+}
+
diff --git a/edit.h b/edit.h
new file mode 100644 (file)
index 0000000..f915467
--- /dev/null
+++ b/edit.h
@@ -0,0 +1,34 @@
+#ifndef _EDIT_H
+#define _EDIT_H
+
+void           edit_item(int item);
+void           get_first_email(char *str, int item);
+void           add_item();
+
+#define EDITW_COLS     (COLS - 6)
+#define EDITW_LINES    (LINES - 5)
+#define EDITW_TOP      2
+#define EDITW_X                3
+
+#define EDITOR_HELPLINE        "?:help c:contact a:address p:phone o:other"
+
+#define TABLINE                1
+
+#define MAX_TAB_FIELDS 7
+
+#define TAB_COLON_POS  28
+#define FIELDS_START_Y 4
+#define FIELDS_START_X 4
+
+enum {
+       TAB_CONTACT,
+       TAB_ADDRESS,
+       TAB_PHONE,
+       TAB_OTHER
+};
+
+#define MAX_TAB                TAB_OTHER
+       
+#define TABS           (MAX_TAB+1)
+
+#endif
diff --git a/estr.c b/estr.c
new file mode 100644 (file)
index 0000000..322f63a
--- /dev/null
+++ b/estr.c
@@ -0,0 +1,613 @@
+
+/*
+ * $Id: estr.c,v 1.8 2002/01/29 11:58:13 jheinonen Exp $
+ *  
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+
+#define USE_FILESEL     1
+/*#undef USE_FILESEL*/
+
+#define ABOOK_SRC      1
+/*#undef ABOOK_SRC*/
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#ifdef ABOOK_SRC
+#      include "abook_curses.h"
+#      include "options.h"
+#else
+#      include <ncurses.h>
+#endif
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+#include "estr.h"
+
+#if defined(HAVE_LOCALE_H) || defined(HAVE_SETLOCALE)
+#      include <locale.h>
+#else
+/*
+ * this is a quick and dirty hack and it is
+ * not likely to work well
+ */
+#      undef iscntrl
+#      undef isprint
+#      define iscntrl(X)       (X < 32)
+#      define isprint(X)       (!iscntrl(X))
+#endif
+
+/*
+ * hmmm, these should be universal and nice :)
+ */
+
+#define                XCTRL(x) ((x) & 31)
+
+#define                ENTER_KEY       KEY_ENTER
+#define                BACKSPACE_KEY   KEY_BACKSPACE
+#define                CANCEL_KEY      XCTRL('g')
+#define                TAB_KEY         '\t'
+
+#ifdef ABOOK_SRC
+#      include "abook.h"
+#      define MALLOC(X)        abook_malloc(X)
+#      define REALLOC(X, XX)   abook_realloc(X, XX)
+#else
+#      define MALLOC(X)        malloc(X)
+#      define REALLOC(X, XX)   realloc(X, XX)
+#endif
+
+/* introduce filesel */
+#ifdef USE_FILESEL
+char            *filesel();
+#endif
+
+#define INITIAL_BUFSIZE                100
+
+char *
+wenter_string(WINDOW *win, const int maxlen, const int flags)
+{
+       int i = 0;
+       int y, x;
+       int ch;
+       char *str = NULL;
+       int size = maxlen > 0 ? maxlen + 1 : INITIAL_BUFSIZE; 
+
+       getyx(win, y, x);
+       str = MALLOC(size);
+
+       for( ;; ) { /* main loop */
+               if(flags & ESTR_DONT_WRAP && x+i > COLS-2) {
+                       mvwaddnstr(win, y, x, str+(1+x+i-COLS), COLS-x-1);
+                       wmove(win, y, COLS-1);
+               } else
+                       wmove(win, y, x + i);
+
+               wclrtoeol(win);
+               wrefresh(win);
+
+               switch( (ch = getch()) ) {
+                       case ENTER_KEY:
+                       case 10:
+                       case 13:
+                               goto out;
+                       case BACKSPACE_KEY:
+                       case 127:
+                               if(i > 0)
+                                       mvwdelch(win, y, x + --i);
+                               continue;       
+                       case CANCEL_KEY:
+                               free(str);
+                               return NULL;
+                       case XCTRL('u'):
+                               i = 0;
+                               break;
+#ifdef USE_FILESEL
+                       case TAB_KEY:
+                               if( ! (flags & ESTR_USE_FILESEL) )
+                                       continue;
+                               i = -1;
+                               free(str);
+                               str = filesel();
+                               goto out;
+#endif
+               }
+               if( !isprint(ch) || iscntrl(ch)
+                       || (maxlen > 0 && i + 1 > maxlen) )
+                       continue;
+               str[i++] = ch;
+               waddch(win,ch);
+               if( i + 1 >= size )
+                       str = REALLOC( str, size *= 2 );
+       }
+out:
+       if( i >= 0 && str != NULL )
+               str[i] = 0;
+       
+       return str;
+}
+
+
+#ifdef USE_FILESEL
+
+/*
+ * filesel.c
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#include <stdio.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+
+#define FILESEL_STATUSLINE      2
+
+#define FILESEL_LIST_TOP        4
+#define FILESEL_LIST_BOTTOM     (LINES-2)
+
+#define FILESEL_LIST_LINES      (FILESEL_LIST_BOTTOM-FILESEL_LIST_TOP)
+#define FILESEL_LIST_COLS       COLS
+
+#define FILESEL_LAST_LIST_ITEM  ( filesel_first_list_item + FILESEL_LIST_LINES - 1 )
+
+
+#define FLSL_TYPE_DIR          0
+#define FLSL_TYPE_OTHER                1
+
+struct filesel_list_item {
+       char filename[256];
+       char type;
+};
+
+#ifndef ABOOK_SRC
+
+#include <errno.h>
+
+static char *
+my_getcwd()
+{
+       char *dir = NULL;
+       int size = 100;
+
+       dir = MALLOC(size);
+
+       while( getcwd(dir, size) == NULL && errno == ERANGE )
+               dir = REALLOC(dir, size *= 2);
+
+       return dir;
+}
+
+#else
+#      include "misc.h"
+#endif
+
+
+#define FILESEL_LAST_ITEM       (filesel_items -1)
+
+int filesel_curitem = -1;
+int filesel_first_list_item = -1;
+
+int filesel_items=0;
+struct filesel_list_item *lst = NULL ;
+
+int filesel_list_capacity = 0;
+
+WINDOW *filesel_list;
+
+static void
+filesel_close_list()
+{
+       free(lst);
+       lst = NULL;
+       filesel_items = 0;
+       filesel_first_list_item = filesel_curitem = -1;
+       filesel_list_capacity = 0;
+}
+
+static void
+filesel_init_list()
+{
+       filesel_list = newwin(FILESEL_LIST_LINES, FILESEL_LIST_COLS,
+                       FILESEL_LIST_TOP, 0);
+}
+
+static void
+init_filesel()
+{
+       if( isendwin() ) {
+               initscr();
+       }
+       
+       cbreak(); noecho();
+       nonl();
+       intrflush(stdscr, FALSE);
+       keypad(stdscr, TRUE);
+       filesel_init_list();
+       clear();
+}
+
+static void
+close_filesel()
+{
+       filesel_close_list();
+       delwin(filesel_list);
+       clear();
+       refresh();
+       endwin();
+}
+
+static void
+filesel_check_list()
+{
+       if( filesel_curitem < 0 && filesel_first_list_item < 0 && filesel_items > 0 )
+               filesel_curitem = filesel_first_list_item = 0;
+}
+
+
+static int
+filesel_add_filesel_list_item(struct filesel_list_item item)
+{
+       if( ++filesel_items > filesel_list_capacity) {
+               filesel_list_capacity =
+               filesel_list_capacity < 1 ? 30:filesel_list_capacity << 1;
+               lst = REALLOC(lst, filesel_list_capacity *
+                       sizeof(struct filesel_list_item) );
+       }
+
+       lst[FILESEL_LAST_ITEM] = item;
+
+       filesel_check_list();
+       
+       return 0;
+}
+
+
+#define FILESEL_DIRS_FIRST
+#define FILESEL_ALPHABETIC_ORDER
+
+#ifdef FILESEL_ALPHABETIC_ORDER
+#      ifndef FILESEL_DIRS_FIRST
+#              define FILESEL_DIRS_FIRST
+#      endif
+#endif
+
+#ifdef FILESEL_ALPHABETIC_ORDER
+static int
+filenamecmp(const void *a, const void *b)
+{
+       return strcmp( ((struct filesel_list_item *)a) -> filename,
+                       ((struct filesel_list_item *)b) -> filename );
+}
+#endif
+
+static void
+filesel_sort_list()
+{
+#ifdef FILESEL_DIRS_FIRST
+        int i, j, fdp=0;
+        struct filesel_list_item tmp;
+
+        while(lst[fdp].type == FLSL_TYPE_DIR)
+               if( ++fdp >= FILESEL_LAST_ITEM )
+                       return;
+
+       for(i = fdp + 1; i < filesel_items; i++) {
+               if(lst[i].type == FLSL_TYPE_DIR ) {
+                       tmp = lst[fdp];
+                       lst[fdp++] = lst[i];
+                       for( j = i; j > fdp ; j--)
+                               lst[j] = lst[j - 1];
+                       lst[fdp] = tmp;
+               }
+       }
+#endif
+#ifdef FILESEL_ALPHABETIC_ORDER
+#ifdef ABOOK_SRC
+       if( options_get_int("filesel_sort") ) {
+#endif
+        if(fdp > 1)
+               qsort((void *)lst, fdp, sizeof(struct filesel_list_item),
+                               filenamecmp );
+
+       qsort((void *)(&lst[fdp]),
+                       FILESEL_LAST_ITEM - fdp + 1,
+                       sizeof(struct filesel_list_item),
+                       filenamecmp );
+#ifdef ABOOK_SRC
+       }
+#endif
+#endif
+}        
+
+static void
+filesel_refresh_statusline()
+{
+       char *p = NULL;
+       
+       move(FILESEL_STATUSLINE,0);
+       clrtoeol();
+
+       mvaddnstr(FILESEL_STATUSLINE, 5,
+                       ( p = my_getcwd() ), COLS-5 );
+
+       free(p);
+}
+
+static void
+filesel_highlight_line(WINDOW *win, int line)
+{
+       int i;
+
+       wattron(win, A_STANDOUT);
+
+       wmove(win, line, 0);
+       for(i = 0; i < FILESEL_LIST_COLS; i++)
+               waddch(win, ' ');
+}
+
+static void
+filesel_print_list_line(int i, int line)
+{
+       if( lst[i].type == FLSL_TYPE_DIR ) {
+               mvwaddch(filesel_list, line, 3, 'd');
+#ifdef A_BOLD
+               wattron(filesel_list, A_BOLD);
+#endif
+       }
+       
+       mvwaddnstr(filesel_list, line, 5, lst[i].filename, COLS - 5);
+}
+
+static void
+filesel_refresh_list()
+{
+       int i, line;
+       
+       werase(filesel_list);
+
+       if( filesel_first_list_item < 0 || filesel_items < 1 ) {
+               refresh();
+               wrefresh(filesel_list);
+               return;
+       }
+
+        for( line = 0, i = filesel_first_list_item ;
+               i <= FILESEL_LAST_LIST_ITEM && i < filesel_items; line++, i++ ) {
+
+               if(i == filesel_curitem) {
+                       filesel_highlight_line(filesel_list, line);
+                       wattron(filesel_list, A_STANDOUT);
+               } else
+                       wattrset(filesel_list, 0);
+               
+               filesel_print_list_line(i, line);
+        }
+
+       refresh();
+        wrefresh(filesel_list);
+}      
+
+static void
+filesel_scroll_up()
+{
+       if( filesel_curitem < 1 )
+               return;
+       filesel_curitem--;
+
+       if( filesel_first_list_item > 0 && filesel_curitem < filesel_first_list_item )
+               filesel_first_list_item--;
+
+       filesel_refresh_list();
+}
+
+static void
+filesel_scroll_down()
+{
+       if( filesel_curitem > filesel_items - 2 )
+               return;
+       filesel_curitem++;
+
+       if( filesel_curitem > FILESEL_LAST_LIST_ITEM )
+               filesel_first_list_item++;
+
+       filesel_refresh_list();
+}
+
+
+static void
+filesel_page_up()
+{
+       if( filesel_curitem < 1 )
+               return;
+       
+       if( filesel_curitem == filesel_first_list_item ) {
+               filesel_curitem = (filesel_curitem -= FILESEL_LIST_LINES) < 0 ? 0 : filesel_curitem;
+               filesel_first_list_item = filesel_curitem;
+       } else
+               filesel_curitem = filesel_first_list_item;
+       
+       filesel_refresh_list();
+}
+
+static void
+filesel_page_down()
+{
+       if( filesel_curitem > filesel_items - 2 )
+               return;
+
+       if( filesel_curitem == FILESEL_LAST_LIST_ITEM ) {
+               filesel_curitem = (filesel_curitem += FILESEL_LIST_LINES) > FILESEL_LAST_ITEM ?
+                       FILESEL_LAST_ITEM : filesel_curitem;
+               filesel_first_list_item = filesel_curitem - FILESEL_LIST_LINES + 1;
+               if( filesel_first_list_item < 0 )
+                       filesel_first_list_item = 0;
+       } else
+               filesel_curitem = FILESEL_LAST_LIST_ITEM < FILESEL_LAST_ITEM ?
+                       FILESEL_LAST_LIST_ITEM : FILESEL_LAST_ITEM;
+
+       filesel_refresh_list();
+}
+
+
+static void
+filesel_goto_home()
+{
+       if(filesel_items > 0) {
+               filesel_first_list_item = 0;
+               filesel_curitem = 0;
+       }
+       filesel_refresh_list();
+}
+
+static void
+filesel_goto_end()
+{
+       if(filesel_items > 0) {
+               filesel_curitem = FILESEL_LAST_ITEM;
+               filesel_first_list_item = filesel_curitem - FILESEL_LIST_LINES + 1;
+               if( filesel_first_list_item < 0 )
+                       filesel_first_list_item = 0;
+       }
+       filesel_refresh_list();
+}
+
+
+static int
+filesel_read_dir()
+{
+       DIR *dir;
+       struct dirent *entry;
+       struct stat st;
+       struct filesel_list_item item;
+
+       dir = opendir(".");
+       for(;;) {
+               entry = readdir(dir);
+               
+               if(entry == NULL)
+                       break;
+
+               stat(entry->d_name, &st);
+               strcpy(item.filename, entry->d_name);
+               item.type = S_ISDIR(st.st_mode) ?
+                       FLSL_TYPE_DIR : FLSL_TYPE_OTHER;
+               filesel_add_filesel_list_item(item);
+       }
+
+       closedir(dir);
+       filesel_sort_list();
+       filesel_check_list();
+       filesel_refresh_statusline();
+       filesel_refresh_list();
+       
+       return 0;
+}
+
+static int
+filesel_enter()
+{
+       char *dir, *newdir;
+
+       if(lst[filesel_curitem].type == FLSL_TYPE_DIR) {
+               dir = my_getcwd();
+               newdir = MALLOC(strlen(dir)+strlen(lst[filesel_curitem].filename) +2 );
+               strcpy(newdir, dir);
+               strcat(newdir, "/");
+               strcat(newdir,lst[filesel_curitem].filename);
+               free(dir);
+               if( (chdir(newdir)) != -1) {
+                       filesel_close_list();
+                       filesel_read_dir();
+               }
+               free(newdir);
+               return 0;
+       } else
+               return 1;
+}
+
+static void
+filesel_goto_item(int ch)
+{
+       int i;
+
+       for(i=filesel_curitem+1; i<filesel_items; i++)
+               if( lst[i].filename[0] == ch ) {
+                       filesel_curitem = i;
+                       break;
+               }
+
+       if( filesel_curitem > FILESEL_LAST_LIST_ITEM)
+               filesel_first_list_item=filesel_curitem;
+
+       filesel_refresh_list();
+}
+
+
+static int
+filesel_loop()
+{
+       int ch;
+       
+       for(;;) {
+               switch( (ch = getch()) ) {
+                       case '\t':
+                       case 'q': return 1;
+                       case 'R': filesel_close_list(); filesel_read_dir();
+                                 break;
+                       case 'k':
+                       case KEY_UP: filesel_scroll_up();       break;
+                       case 'j':
+                       case KEY_DOWN: filesel_scroll_down();   break;
+                       case 'K':
+                       case KEY_PPAGE: filesel_page_up();      break;
+                       case 'J':
+                       case KEY_NPAGE: filesel_page_down();    break;
+
+                       case KEY_HOME: filesel_goto_home();     break;
+                       case KEY_END: filesel_goto_end();       break;
+
+                       case '\n':
+                       case '\r': if( filesel_enter() ) {
+                                          return 0;
+                               }
+                                 break;
+                       default: filesel_goto_item(ch);
+               }
+       }
+}
+
+char *
+filesel()
+{
+       char *dir, *tmp, *ptr = NULL;
+       
+        init_filesel();
+       filesel_read_dir();
+
+       if( !filesel_loop() ) {
+               dir = my_getcwd();
+               tmp = MALLOC(strlen(dir) + strlen(lst[filesel_curitem].filename) + 2);
+               strcpy(tmp,dir);
+               strcat(tmp, "/");
+               strcat(tmp, lst[filesel_curitem].filename);
+               ptr = strdup(tmp);
+               free(tmp);
+               free(dir);
+       }
+       
+        close_filesel();
+
+       return ptr;
+}
+
+#endif /* USE_FILESEL */
+
diff --git a/estr.h b/estr.h
new file mode 100644 (file)
index 0000000..834da1e
--- /dev/null
+++ b/estr.h
@@ -0,0 +1,19 @@
+
+/*
+ * $Id: estr.h,v 1.4 2001/08/23 09:39:56 jheinonen Exp $
+ *
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#ifndef _ESTR_H
+#define _ESTR_H
+
+char   *wenter_string(WINDOW *win, const int maxlen, const int flags);
+
+#define                ESTR_USE_FILESEL        1
+#define                ESTR_DONT_WRAP          2
+
+#endif
+
diff --git a/filter.c b/filter.c
new file mode 100644 (file)
index 0000000..902c481
--- /dev/null
+++ b/filter.c
@@ -0,0 +1,1521 @@
+
+/*
+ * $Id: filter.c,v 1.15 2002/01/19 11:07:02 jheinonen Exp $
+ *
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "abook_curses.h"
+#include "filter.h"
+#include "abook.h"
+#include "database.h"
+#include "edit.h"
+#include "list.h"
+#include "misc.h"
+#include "options.h"
+#include <assert.h>
+
+extern int items;
+extern list_item *database;
+extern struct abook_field abook_fields[];
+
+/*
+ * function declarations
+ */
+
+/*
+ * import filter prototypes
+ */
+
+static int      ldif_parse_file(FILE *handle);
+static int     mutt_parse_file(FILE *in);
+static int     pine_parse_file(FILE *in);
+static int     csv_parse_file(FILE *in);
+
+/*
+ * export filter prototypes
+ */
+
+static int      ldif_export_database(FILE *out, struct db_enumerator e);
+static int     html_export_database(FILE *out, struct db_enumerator e);
+static int     pine_export_database(FILE *out, struct db_enumerator e);
+static int     csv_export_database(FILE *out, struct db_enumerator e);
+static int     gcrd_export_database(FILE *out, struct db_enumerator e);
+static int     mutt_alias_export(FILE *out, struct db_enumerator e);
+static int     elm_alias_export(FILE *out, struct db_enumerator e);
+static int     text_export_database(FILE *out, struct db_enumerator e);
+static int     spruce_export_database(FILE *out, struct db_enumerator e);
+
+/*
+ * end of function declarations
+ */
+
+struct abook_input_filter i_filters[] = {
+       { "abook", "abook native format", parse_database },
+       { "ldif", "ldif / Netscape addressbook", ldif_parse_file },
+       { "mutt", "mutt alias", mutt_parse_file },
+       { "pine", "pine addressbook", pine_parse_file },
+       { "csv", "comma separated values", csv_parse_file },
+       { "\0", NULL, NULL }
+};
+
+struct abook_output_filter e_filters[] = {
+       { "abook", "abook native format", write_database },
+       { "ldif", "ldif / Netscape addressbook (.4ld)", ldif_export_database },
+       { "mutt", "mutt alias", mutt_alias_export },
+       { "html", "html document", html_export_database },
+       { "pine", "pine addressbook", pine_export_database },
+       { "gcrd", "GnomeCard (VCard) addressbook", gcrd_export_database },
+       { "csv", "comma separated values", csv_export_database },
+       { "elm", "elm alias", elm_alias_export },
+       { "text", "plain text", text_export_database },
+       { "spruce", "Spruce address book", spruce_export_database },
+       { "\0", NULL, NULL }
+};
+
+/*
+ * common functions
+ */
+
+void
+print_filters()
+{
+       int i;
+       
+       puts("input:");
+       for(i=0; *i_filters[i].filtname ; i++)
+               printf("\t%s\t%s\n", i_filters[i].filtname,
+                       i_filters[i].desc);
+
+       putchar('\n');
+       
+       puts("output:");
+       for(i=0; *e_filters[i].filtname ; i++)
+               printf("\t%s\t%s\n", e_filters[i].filtname,
+                       e_filters[i].desc);
+
+       putchar('\n');
+}
+
+static int
+number_of_output_filters()
+{
+       int i;
+
+       for(i=0; *e_filters[i].filtname ; i++)
+               ;
+
+       return i;
+}
+
+static int
+number_of_input_filters()
+{
+       int i;
+
+       for(i=0; *i_filters[i].filtname ; i++)
+               ;
+
+       return i;
+}
+
+static char *
+get_real_name()
+{
+       char *username = getenv("USER");
+       struct passwd *pwent;
+       int rtn;
+       char *tmp;
+
+       pwent = getpwnam(username);
+
+       if( (tmp = (char *)malloc(strlen(pwent->pw_gecos) +1)) == NULL)
+               return strdup(username);
+
+       rtn = sscanf(pwent->pw_gecos, "%[^,]", tmp);
+       if (rtn == EOF || rtn == 0) {
+               free(tmp);
+               return strdup(username);
+       } else
+               return tmp;
+}
+
+/*
+ * import
+ */
+       
+static int             i_read_file(char *filename, int (*func) (FILE *in));
+
+static void
+import_screen()
+{
+       int i;
+       
+       clear();
+
+       refresh_statusline();
+       headerline("import database");
+
+       mvaddstr(3, 1, "please select a filter");
+       
+
+       for(i=0; *i_filters[i].filtname ; i++)
+               mvprintw(5 + i, 6, "%c -\t%s\t%s\n", 'a' + i,
+                       i_filters[i].filtname,
+                       i_filters[i].desc);
+
+       mvprintw(6 + i, 6, "x -\tcancel");
+}
+
+int
+import_database()
+{
+       int filter;
+       char *filename;
+       int tmp = items;
+
+       import_screen();
+       
+       filter = getch() - 'a';
+       if(filter == 'x' - 'a' ||
+               filter >= number_of_input_filters() || filter < 0) {
+               refresh_screen();
+               return 1;
+       }
+       
+       mvaddstr(5+filter, 2, "->");
+       
+       filename = ask_filename("Filename: ", 1);
+       if( !filename ) {
+               refresh_screen();
+               return 2;
+       }
+               
+       if(  i_read_file(filename, i_filters[filter].func ) )
+               statusline_msg("Error occured while opening the file");
+       else
+       if( tmp == items )
+               statusline_msg("Hmm.., file seems not to be a valid file");
+       
+       refresh_screen();
+       free(filename);
+
+       return 0;
+}
+
+
+
+static int
+i_read_file(char *filename, int (*func) (FILE *in))
+{
+       FILE *in;
+       int ret = 0;
+
+       if( ( in = abook_fopen( filename, "r" ) ) == NULL )
+               return 1;
+
+       ret = (*func) (in);
+
+       fclose(in);
+
+       return ret;     
+}
+
+int
+import(char filtname[FILTNAME_LEN], char *filename)
+{
+       int i;
+       int tmp = items;
+       int ret = 0;
+
+       for(i=0;; i++) {
+               if( ! strncmp(i_filters[i].filtname, filtname, FILTNAME_LEN) )
+                       break;
+               if( ! *i_filters[i].filtname ) {
+                       i = -1;
+                       break;
+               }
+       }
+
+       if( i<0 )
+               return -1;
+
+       if( !strcmp(filename, "-") ) {
+               struct stat s;
+               if( (fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode))
+                       ret = 1;
+               else
+                       ret = (*i_filters[i].func) (stdin);
+       } else
+               ret =  i_read_file(filename, i_filters[i].func);
+       
+       if( tmp == items )
+               ret = 1;
+       
+       return ret;
+}
+
+/*
+ * export
+ */
+
+static int             e_write_file(char *filename,
+               int (*func) (FILE *in, struct db_enumerator e), int mode);
+
+static void
+export_screen()
+{
+       int i;
+       
+       clear();
+
+
+       refresh_statusline();
+       headerline("export database");
+
+       mvaddstr(3, 1, "please select a filter");
+       
+
+       for(i=0; *e_filters[i].filtname ; i++)
+               mvprintw(5 + i, 6, "%c -\t%s\t%s\n", 'a' + i,
+                       e_filters[i].filtname,
+                       e_filters[i].desc);
+
+       mvprintw(6 + i, 6, "x -\tcancel");
+}
+
+int
+export_database()
+{
+       int filter;
+       int enum_mode = ENUM_ALL;
+       char *filename;
+
+       export_screen();
+       
+       filter = getch() - 'a';
+       if(filter == 'x' - 'a' ||
+               filter >= number_of_output_filters(e_filters) || filter < 0) {
+               refresh_screen();
+               return 1;
+       }
+       
+       mvaddstr(5+filter, 2, "->");
+
+       if( selected_items() ) {
+               statusline_addstr("Export All/Selected/Cancel (A/s/c)");
+               switch( tolower(getch()) ) {
+                       case 's':
+                               enum_mode = ENUM_SELECTED;
+                               break;
+                       case 'c':
+                               clear_statusline();
+                               return 1;
+               }
+               clear_statusline();
+       }
+       
+       filename = ask_filename("Filename: ", 0);
+       if( !filename ) {
+               refresh_screen();
+               return 2;
+       }
+       
+       if(  e_write_file(filename, e_filters[filter].func, enum_mode ) )
+               statusline_msg("Error occured while exporting");
+       
+       refresh_screen();
+       free(filename);
+
+       return 0;
+}
+
+static int
+e_write_file(char *filename, int (*func) (FILE *in, struct db_enumerator e),
+               int mode)
+{
+       FILE *out;
+       int ret = 0;
+       struct db_enumerator enumerator = init_db_enumerator(mode);
+
+       if( (out = fopen(filename, "a")) == NULL )
+               return 1;
+
+       if( ftell(out) )
+               return 1;
+
+       ret = (*func) (out, enumerator);
+       
+       fclose(out);
+       
+       return ret;
+}
+
+int
+fexport(char filtname[FILTNAME_LEN], FILE *handle, int enum_mode)
+{
+       int i;
+       struct db_enumerator e = init_db_enumerator(enum_mode);
+
+       for(i=0;; i++) {
+               if( ! strncmp(e_filters[i].filtname, filtname, FILTNAME_LEN) )
+                       break;
+               if( ! *e_filters[i].filtname ) {
+                       i = -1;
+                       break;
+               }
+       }
+
+       return (e_filters[i].func) (handle, e);
+}
+
+       
+
+int
+export(char filtname[FILTNAME_LEN], char *filename)
+{
+       const int mode = ENUM_ALL;
+       int i;
+       int ret = 0;
+       struct db_enumerator e = init_db_enumerator(mode);
+       
+       for(i=0;; i++) {
+               if( ! strncmp(e_filters[i].filtname, filtname, FILTNAME_LEN) )
+                       break;
+               if( ! *e_filters[i].filtname ) {
+                       i = -1;
+                       break;
+               }
+       }
+
+       if( i<0 )
+               return -1;
+
+       if( !strcmp(filename, "-") )
+               ret = (e_filters[i].func) (stdout, e);
+       else
+               ret =  e_write_file(filename, e_filters[i].func, mode);
+
+       return ret;
+}
+
+/*
+ * end of common functions
+ */
+
+/*
+ * ldif import
+ */
+
+#include "ldif.h"
+
+static void    ldif_fix_string(char *str);
+
+#define        LDIF_ITEM_FIELDS        16
+
+typedef char*  ldif_item[LDIF_ITEM_FIELDS];
+
+static ldif_item ldif_field_names = {
+       "cn",   
+       "mail",
+       "streetaddress",
+       "streetaddress2",
+        "locality",
+       "st",
+       "postalcode",
+       "countryname",
+       "homephone",
+       "description",
+       "homeurl",
+       "facsimiletelephonenumber",
+       "cellphone",
+       "xmozillaanyphone",
+       "xmozillanickname",
+       "objectclass", /* this must be the last entry */
+};
+
+static int ldif_conv_table[LDIF_ITEM_FIELDS] = {
+       NAME,           /* "cn" */
+       EMAIL,          /* "mail" */
+       ADDRESS,        /* "streetaddress" */
+       ADDRESS2,       /* "streetaddress2" */     
+        CITY,          /* "locality" */
+       STATE,          /* "st" */
+       ZIP,            /* "postalcode" */
+       COUNTRY,        /* "countryname" */
+       PHONE,          /* "homephone" */
+       NOTES,          /* "description" */
+       URL,            /* "homeurl" */
+       FAX,            /* "facsimiletelephonenumber" */
+       MOBILEPHONE,    /* "cellphone" */
+       WORKPHONE,      /* "xmozillaanyphone" */
+       NICK,           /* "xmozillanickname" */
+       -1,             /* "objectclass" */ /* this must be the last entry */
+};
+
+
+static char * 
+ldif_read_line(FILE *in)
+{
+       char *buf = NULL;
+       char *ptr, *tmp;
+       long pos;
+       int i;
+
+       for(i = 1;;i++) {
+               char *line;
+
+               pos = ftell(in);
+               line = getaline(in);
+               
+               if( feof(in) || !line )
+                       break;
+               
+               if(i == 1) {
+                       buf = line;
+                       continue;
+               }
+               
+               if(*line != ' ') {
+                       fseek(in, pos, SEEK_SET);
+                       free(line);
+                       break;
+               }
+
+               ptr = line;
+               while( *ptr == ' ')
+                       ptr++;
+
+               tmp = buf;
+               buf = strconcat(buf, ptr, NULL);
+               free(tmp);
+               free(line);
+       }
+
+       if(buf && *buf == '#' ) {
+               free(buf);
+               return NULL;
+       }
+               
+       return buf;
+}
+
+static void
+ldif_add_item(ldif_item ldif_item)
+{
+       list_item abook_item;
+       int i;
+
+       memset(abook_item, 0, sizeof(abook_item));
+       
+       if( !ldif_item[LDIF_ITEM_FIELDS -1] )
+               goto bail_out;
+       
+
+       for(i=0; i < LDIF_ITEM_FIELDS; i++) {
+               if(ldif_conv_table[i] >= 0 && ldif_item[i] && *ldif_item[i] )
+                       abook_item[ldif_conv_table[i]] = strdup(ldif_item[i]);
+       }
+
+       add_item2database(abook_item);
+
+bail_out:
+       for(i=0; i < LDIF_ITEM_FIELDS; i++)
+               my_free(ldif_item[i]);
+
+}
+
+static void
+ldif_convert(ldif_item item, char *type, char *value)
+{
+       int i;
+
+       if( !strcmp(type, "dn") ) {
+               ldif_add_item(item);
+               return;
+       }
+
+       for(i=0; i < LDIF_ITEM_FIELDS; i++) {
+               if( !safe_strcmp(ldif_field_names[i], type) && *value ) {
+                       if( i == LDIF_ITEM_FIELDS -1) /* this is a dirty hack */
+                               if( safe_strcmp("person", value))
+                                       break;
+                       if(item[i])
+                               my_free(item[i]);
+                       item[i] = strdup(value);
+               }
+       }
+}
+
+static int
+ldif_parse_file(FILE *handle)
+{
+       char *line = NULL;
+       char *type, *value;
+       int vlen;
+       ldif_item item;
+
+       memset(item, 0, sizeof(item));
+
+       do {
+               if( ! (line = ldif_read_line(handle)) )
+                       continue;
+
+               if( -1 == ( str_parse_line(line, &type, &value, &vlen)) ) {
+                       my_free(line);
+                       continue; /* just skip the errors */
+               }
+                               
+               ldif_fix_string(value);
+
+               ldif_convert(item, type, value);
+
+               my_free(line);
+       } while ( !feof(handle) );
+
+       ldif_convert(item, "dn", "");
+
+       return 0;
+}
+
+static void
+ldif_fix_string(char *str)
+{
+       int i, j;
+
+       for( i = 0, j = 0; j < strlen(str); i++, j++)
+               str[i] = ( str[j] == (char)0xc3 ?
+                               (char) str[++j] + (char) 0x40 :
+                               str[j] );
+
+       str[i] = 0;
+}
+
+/*
+ * end of ldif import
+ */
+
+/*
+ * mutt alias import filter
+ */
+
+#include "getname.h"
+
+static int
+mutt_read_line(FILE *in, char **alias, char **rest)
+{
+       char *line, *ptr, *tmp;
+
+       if( !(line = ptr = getaline(in)) )
+               return 1; /* error / EOF */
+
+       while( ISSPACE(*ptr) )
+               ptr++;
+
+       if( strncmp("alias", ptr, 5) ) {
+               free(line);
+               return 1;
+       }
+               
+       ptr += 5;
+
+       while( ISSPACE(*ptr) )
+               ptr++;
+
+       tmp = ptr;
+
+       while( ! ISSPACE(*ptr) )
+               ptr++;
+
+       if( (*alias = (char *)malloc(ptr-tmp+1)) == NULL) {
+               free(line);
+               return 1;
+       }
+
+       strncpy(*alias, tmp, ptr-tmp);
+       *(*alias + (ptr - tmp)) = 0;
+
+       while( ISSPACE(*ptr) )
+               ptr++;
+
+       *rest = strdup(ptr);    
+
+       free(line);
+       return 0;
+}
+
+static void
+mutt_parse_email(list_item item)
+{
+       char *line = item[NAME];
+       char *start = line, *tmp;
+       char *name, *email;
+       int i = 0;
+
+       tmp = strconcat("From: ", line, NULL);
+       getname(tmp, &name, &email);
+       free(tmp);
+
+       if(name)
+               item[NAME] = name;
+       else
+               return;
+       if(email)
+               item[EMAIL] = email;
+       else
+               return;
+       
+       while( (start = strchr(start, ',')) && i++ < MAX_EMAILS - 1) {
+               tmp = strconcat("From: ", ++start, NULL);
+               getname(tmp, &name, &email);
+               free(tmp);
+               free(name);
+               if(email) {
+                       if(*email) {
+                               tmp = strconcat(item[EMAIL], ",", email, NULL);
+                               free(item[EMAIL]);
+                               item[EMAIL] = tmp;
+                       } else {
+                               my_free(email);
+                       }
+               }
+       }
+}
+
+static int
+mutt_parse_file(FILE *in)
+{
+       list_item item;
+
+       for(;;) {
+               memset(item, 0, sizeof(item));
+               
+               if( !mutt_read_line(in, &item[NICK],
+                               &item[NAME]) )
+                       mutt_parse_email(item);
+
+               if( feof(in) ) {
+                       free_list_item(item);
+                       break;
+               }
+
+               add_item2database(item);
+       }
+
+       return 0;
+}
+
+/*
+ * end of mutt alias import filter
+ */
+
+
+/*
+ * ldif export filter
+ */
+
+static void
+ldif_fput_type_and_value(FILE *out,char *type, char *value )
+{
+       char *tmp;
+
+       tmp = ldif_type_and_value(type, value, strlen(value));
+
+       fputs(tmp, out);
+
+       free(tmp);
+}
+
+static int
+ldif_export_database(FILE *out, struct db_enumerator e)
+{
+       char email[MAX_EMAILSTR_LEN];
+
+       fprintf(out, "version: 1\n");
+
+       db_enumerate_items(e) {
+               char *tmp;
+               int j;
+               get_first_email(email, e.item);
+
+               tmp = mkstr("cn=%s,mail=%s", database[e.item][NAME], email);
+               ldif_fput_type_and_value(out, "dn", tmp);
+               free(tmp);
+
+               for(j=0; j < LDIF_ITEM_FIELDS; j++) {
+                       if(ldif_conv_table[j] >= 0) {
+                               if(ldif_conv_table[j] == EMAIL)
+                                       ldif_fput_type_and_value(out,
+                                               ldif_field_names[j], email);
+                               else if(database[e.item][ldif_conv_table[j]])
+                                       ldif_fput_type_and_value(out,
+                                               ldif_field_names[j],
+                                               database[e.item][ldif_conv_table[j]]);
+                       }
+               }
+
+               fprintf(out, "objectclass: top\n"
+                               "objectclass: person\n\n");
+       }
+
+       return 0;
+}
+
+/*
+ * end of ldif export filter
+ */
+
+/*
+ * html export filter
+ */
+
+static void            html_export_write_head(FILE *out, int extra_column);
+static void            html_export_write_tail(FILE *out);
+
+static int
+html_export_database(FILE *out, struct db_enumerator e)
+{
+       char tmp[MAX_EMAILSTR_LEN];
+       int extra_column = options_get_int("extra_column");
+
+       if( items < 1 )
+               return 2;
+
+       extra_column = (extra_column > 2 && extra_column < ITEM_FIELDS) ?
+               extra_column : PHONE;
+
+       html_export_write_head(out, extra_column);
+
+       db_enumerate_items(e) {
+               get_first_email(tmp, e.item);
+               if (*tmp)
+                   fprintf(out, "<tr>\n<td><a href=\"mailto:%s\">%s</a>\n",
+                           tmp,
+                           database[e.item][NAME] );
+               else
+                   fprintf(out, "<tr>\n<td>%s\n",
+                           database[e.item][NAME] );
+
+               fprintf(out, "<td>%s\n<td>%s\n",
+                               database[e.item][EMAIL],
+                               safe_str(database[e.item][extra_column]) );
+               fprintf(out, "</tr>\n\n");
+       }
+
+       html_export_write_tail(out);
+
+       return 0;
+}
+
+
+static void
+html_export_write_head(FILE *out, int extra_column)
+{
+       char *realname = get_real_name();
+
+       fprintf(out, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n");
+       fprintf(out, "<html>\n<head>\n  <title>%s's addressbook</title>",
+                       realname );
+       fprintf(out, "\n</head>\n<body>\n");
+       fprintf(out, "\n<h2>%s's addressbook</h2>\n", realname );
+       fprintf(out, "<br><br>\n\n");
+
+       fprintf(out, "<center><table border>\n");
+       fprintf(out, "\n<tr><th>Name<th>E-mail address(es)<th>%s</tr>\n\n",
+                       abook_fields[extra_column].name);
+
+       free(realname);
+}
+
+static void
+html_export_write_tail(FILE *out)
+{
+       fprintf(out, "\n</table></center>\n");
+       fprintf(out, "\n</body>\n</html>\n");
+}
+       
+/*
+ * end of html export filter
+ */
+
+
+/*
+ * pine addressbook import filter
+ */
+
+static void
+pine_fixbuf(char *buf)
+{
+       int i,j;
+
+       for(i=0,j=0; j < strlen(buf); i++, j++)
+               buf[i] = buf[j] == '\n' ? buf[++j] : buf[j];
+}
+
+static void
+pine_convert_emails(char *s)
+{
+       int i;
+       char *tmp;
+
+       if( s == NULL || *s != '(' )
+               return;
+
+       for(i=0; s[i]; i++ )
+               s[i] = s[i+1];
+
+       if( ( tmp = strchr(s,')')) )
+               *tmp=0;
+       
+       for(i=1; ( tmp = strchr(s, ',') ) != NULL ; i++, s=tmp+1 )
+               if( i > MAX_EMAILS - 1 ) {
+                       *tmp = 0;
+                       break;  
+               }
+
+}
+
+static void
+pine_parse_buf(char *buf)
+{
+       list_item item;
+       char *start = buf;
+       char *end;
+       char tmp[400];
+       int i, len, last;
+       int pine_conv_table[]= {NICK, NAME, EMAIL, -1, NOTES};
+
+       memset(&item, 0, sizeof(item) );
+       
+       for(i=0, last=0; !last ; i++) {
+               if( ! (end = strchr(start, '\t')) )
+                       last=1;
+               
+               len = last ? strlen(start) : (int) (end-start);
+               len = min(len, 400-1);
+       
+               if(i < sizeof(pine_conv_table) / sizeof(*pine_conv_table)
+                               && pine_conv_table[i] >= 0) {
+                       strncpy(tmp, start, len);
+                       tmp[len] = 0;
+                       item[pine_conv_table[i]] = strdup(tmp);
+               }
+               start = end + 1;
+       }
+       
+       pine_convert_emails(item[EMAIL]);
+       add_item2database(item);
+}
+               
+
+#define LINESIZE       1024
+
+static int
+pine_parse_file(FILE *in)
+{
+       char line[LINESIZE];
+       char *buf = NULL;
+       char *ptr;
+       int i;
+
+       fgets(line, LINESIZE, in);      
+       
+       while(!feof(in)) {
+               for(i = 2;;i++) {
+                       buf = (char *) realloc(buf, i*LINESIZE);
+                       if(i == 2)
+                               strcpy(buf, line);
+                       fgets(line, LINESIZE, in);
+                       ptr=(char *)&line;
+                       if(*ptr != ' ' || feof(in) )
+                               break;
+                       else
+                               while( *ptr == ' ')
+                                       ptr++;
+                               
+                       strcat(buf, ptr);
+               }
+               if( *buf == '#' ) {
+                       my_free(buf);
+                       continue;
+               }
+               pine_fixbuf(buf);
+
+               pine_parse_buf(buf);
+
+               my_free(buf);
+       }
+
+       return 0;
+}
+
+/*
+ * end of pine addressbook import filter
+ */
+
+
+/*
+ * pine addressbook export filter
+ *
+ *  filter doesn't wrap the lines as it should but Pine seems to handle
+ *  created files without problems - JH
+ */
+
+static int
+pine_export_database(FILE *out, struct db_enumerator e)
+{
+       db_enumerate_items(e) {
+               fprintf(out, have_multiple_emails(e.item) ?
+                               "%s\t%s\t(%s)\t\t%s\n" : "%s\t%s\t%s\t\t%s\n",
+                               safe_str(database[e.item][NICK]),
+                               safe_str(database[e.item][NAME]),
+                               safe_str(database[e.item][EMAIL]),
+                               safe_str(database[e.item][NOTES])
+                               );
+       }
+
+       return 0;
+}
+
+/*
+ * end of pine addressbook export filter
+ */
+
+
+/*
+ * csv import filter
+ */
+
+/* FIXME
+ * these files should be parsed according to a certain
+ * lay out, or the default if layout is not given, at 
+ * the moment only default is done...
+ */ 
+
+#define CSV_COMMENT_CHAR       '#'
+
+static int csv_conv_table[] = {
+       NAME,
+       EMAIL,
+       PHONE,
+       NOTES,
+       NICK
+};
+
+static void
+csv_convert_emails(char *s)
+{
+       int i;
+       char *tmp;
+
+       if( s == NULL )
+               return;
+
+       for(i=1; ( tmp = strchr(s, ',') ) != NULL ; i++, s = tmp + 1 )
+               if( i > MAX_EMAILS - 1 ) {
+                       *tmp = 0;
+                       break;  
+               }
+
+}
+
+static char *
+csv_remove_quotes(char *s)
+{
+       char *copy, *trimmed;
+       int len;
+       
+       copy = trimmed = strdup(s);
+       strtrim(trimmed);
+       
+       len = strlen(trimmed);
+       if(trimmed[len - 1] == '\"' && *trimmed == '\"') {
+               if(len < 3) {
+                       my_free(copy);
+                       return NULL;
+               }
+               trimmed[len - 1] = 0;
+               trimmed++;
+               trimmed = strdup(trimmed);
+               free(copy);
+               return trimmed;
+       }
+
+       my_free(copy);
+       return strdup(s);
+}
+
+static void
+csv_store_field(list_item item, char *s, int field)
+{
+       char *newstr = NULL;
+
+       if(!s || !*s)
+               return;
+
+       if( !(newstr = csv_remove_quotes(s)) )
+               return;
+
+       if(field < (sizeof(csv_conv_table) / sizeof(*csv_conv_table))
+                       && csv_conv_table[field] >= 0) {
+               item[csv_conv_table[field]] = newstr;
+       }
+}
+
+static int
+csv_is_valid_quote_end(char *p)
+{
+       if(*p != '\"')
+               return FALSE;
+
+       for(p++; *p; p++) {
+               if(*p == ',')
+                       return TRUE;
+               else if(!ISSPACE(*p))
+                       return FALSE;
+       }
+
+       return TRUE;
+}
+
+static int
+csv_is_valid_quote_start(char *p)
+{
+       for(; *p; p++) {
+               if(*p == '\"')
+                       return TRUE;
+               else if(!ISSPACE(*p))
+                       return FALSE;
+       }
+
+       return FALSE;
+}
+
+static void
+csv_parse_line(char *line)
+{
+       char *p, *start;
+       int field;
+       int in_quote = FALSE;
+       list_item item;
+
+       memset(item, 0, sizeof(item));
+
+       for(p = start = line, field = 0; *p; p++) {
+               if(in_quote) {
+                       if(csv_is_valid_quote_end(p))
+                               in_quote = FALSE;
+               } else {
+                       if ( (((p - start) / sizeof (char)) < 2 ) &&
+                               csv_is_valid_quote_start(p) )
+                               in_quote = TRUE;
+               }
+
+               if( *p == ',' && !in_quote) {
+                       *p = 0;
+                       csv_store_field(item, start, field);
+                       field++;
+                       start = p + 1;
+               }
+       }
+       /*
+        * store last field
+        */
+       csv_store_field(item, start, field);
+
+       csv_convert_emails(item[EMAIL]);
+       add_item2database(item);
+}
+
+
+static int
+csv_parse_file(FILE *in)
+{
+       char *line = NULL;
+
+       while(!feof(in)) {
+               line = getaline(in);
+
+               if(line && *line && *line != CSV_COMMENT_CHAR)
+                       csv_parse_line(line);
+
+               my_free(line);
+       }
+
+       return 0;
+}
+
+/*
+ * end of csv import filter
+ */
+
+/*
+ * csv addressbook export filter
+ */
+
+static int
+csv_export_database(FILE *out, struct db_enumerator e)
+{
+       int j;
+       int csv_export_fields[] = {
+               NAME,
+               EMAIL,
+               PHONE,
+               NOTES,
+               NICK,
+               -1
+       };
+
+       db_enumerate_items(e) {
+               for(j = 0; csv_export_fields[j] >= 0; j++) {
+                       fprintf(out,(
+               strchr(safe_str(database[e.item][csv_export_fields[j]]), ',') ||
+               strchr(safe_str(database[e.item][csv_export_fields[j]]), '\"')
+                       ) ?
+                               "\"%s\"" : "%s",
+                               safe_str(database[e.item][csv_export_fields[j]])
+                               );
+                       if(csv_export_fields[j+1] >= 0)
+                               fputc(',', out);
+               }
+               fputc('\n', out);
+       }
+               
+
+
+       return 0;
+}
+
+/*
+ * end of csv export filter
+ */
+
+
+/*
+ * GnomeCard (VCard) addressbook export filter
+ */
+
+static int
+gcrd_export_database(FILE *out, struct db_enumerator e)
+{
+       char emails[MAX_EMAILS][MAX_EMAIL_LEN];
+       int j;
+       char *name;
+
+       db_enumerate_items(e) {
+               fprintf(out, "BEGIN:VCARD\nFN:%s\n",
+                               safe_str(database[e.item][NAME]));
+
+               name = get_surname(database[e.item][NAME]);
+               for( j = strlen(database[e.item][NAME]) - 1; j >= 0; j-- ) {
+                       if(database[e.item][NAME][j] == ' ')
+                               break;
+               } 
+               fprintf(out, "N:%s;%.*s\n",
+                       safe_str(name),
+                       j,
+                       safe_str(database[e.item][NAME])
+                       ); 
+
+               free(name);
+
+               if ( database[e.item][ADDRESS] )
+                       fprintf(out, "ADR:;;%s;%s;%s;%s;%s;%s\n",
+                               safe_str(database[e.item][ADDRESS]),
+                               safe_str(database[e.item][ADDRESS2]),                           
+                               safe_str(database[e.item][CITY]),
+                               safe_str(database[e.item][STATE]),
+                               safe_str(database[e.item][ZIP]),
+                               safe_str(database[e.item][COUNTRY])
+                               );
+               
+               if (database[e.item][PHONE])
+                       fprintf(out, "TEL;HOME:%s\n", database[e.item][PHONE]);
+               if (database[e.item][WORKPHONE])
+                       fprintf(out, "TEL;WORK:%s\n", database[e.item][WORKPHONE]);
+               if (database[e.item][FAX])
+                       fprintf(out, "TEL;FAX:%s\n", database[e.item][FAX]);
+               if (database[e.item][MOBILEPHONE])
+                       fprintf(out, "TEL;CELL:%s\n", database[e.item][MOBILEPHONE]);
+
+               if ( database[e.item][EMAIL] ) {
+                       split_emailstr(e.item, emails);
+                       for(j=0; j < MAX_EMAILS ; j++) {
+                               if ( *emails[j] ) 
+                                       fprintf(out, "EMAIL;INTERNET:%s\n",
+                                               emails[j]);
+                       }
+               }
+               
+               if ( database[e.item][NOTES] ) 
+                       fprintf(out, "NOTE:%s\n", database[e.item][NOTES]);
+               if (database[e.item][URL])
+                       fprintf(out, "URL:%s\n",  database[e.item][URL]);
+
+               fprintf(out, "END:VCARD\n\n");
+               
+       }
+
+       return 0;
+}
+
+/*
+ * end of GnomeCard export filter
+ */
+
+
+/*
+ * mutt alias export filter
+ */
+
+static char *
+mutt_alias_genalias(int i)
+{
+       char *tmp, *pos;
+       
+       if(database[i][NICK])
+               return strdup(database[i][NICK]);
+
+       tmp = strdup(database[i][NAME]);
+
+       if( ( pos = strchr(tmp, ' ') ) )
+               *pos = 0;
+
+       strlower(tmp);
+
+       return tmp;     
+}
+
+static int
+mutt_alias_export(FILE *out, struct db_enumerator e)
+{
+       char email[MAX_EMAIL_LEN];
+       char *alias = NULL;
+
+       db_enumerate_items(e) {
+               alias = mutt_alias_genalias(e.item);
+
+               get_first_email(email, e.item);
+               fprintf(out, *email ? "alias %s %s <%s>\n": "alias %s %s%s\n",
+                               alias,
+                               database[e.item][NAME],
+                               email);
+               my_free(alias);
+       }
+
+       return 0;
+}
+
+/*
+ * end of mutt alias export filter
+ */
+
+
+/*
+ * printable export filter
+ */
+
+
+static void
+text_write_address_us(FILE *out, int i) {
+       fprintf(out, "\n%s", database[i][ADDRESS]);
+
+       if (database[i][ADDRESS2])
+               fprintf(out, "\n%s", database[i][ADDRESS2]);
+
+       if (database[i][CITY])
+               fprintf(out, "\n%s", database[i][CITY]);
+               
+       if (database[i][STATE] || database[i][ZIP]) {
+               fputc('\n', out);
+               
+               if(database[i][STATE]) {
+                       fprintf(out, "%s", database[i][STATE]);
+                       if(database[i][ZIP])
+                               fputc(' ', out);
+               }
+
+               if(database[i][ZIP])
+                       fprintf(out, "%s", database[i][ZIP]);
+       }
+
+       if (database[i][COUNTRY])
+               fprintf(out, "\n%s", database[i][COUNTRY]);
+}
+
+
+static void
+text_write_address_uk(FILE *out, int i) {
+       int j;
+
+       for (j = ADDRESS; j <= COUNTRY; j++)
+               if (database[i][j])
+                       fprintf(out, "\n%s", database[i][j]);
+}
+
+static void
+text_write_address_eu(FILE *out, int i) {
+       fprintf(out, "\n%s", database[i][ADDRESS]);
+
+       if (database[i][ADDRESS2])
+               fprintf(out, "\n%s", database[i][ADDRESS2]);
+
+       if (database[i][ZIP] || database[i][CITY]) {
+               fputc('\n', out);
+
+               if(database[i][ZIP]) {
+                       fprintf(out, "%s", database[i][ZIP]);
+                       if(database[i][CITY])
+                               fputc(' ', out);
+               }
+
+               if(database[i][CITY])
+                       fprintf(out, "%s", database[i][CITY]);
+       }
+       
+       if (database[i][STATE])
+               fprintf(out, "\n%s", database[i][STATE]);
+
+       if (database[i][COUNTRY])
+               fprintf(out, "\n%s", database[i][COUNTRY]);
+}
+
+static int
+text_export_database(FILE * out, struct db_enumerator e)
+{
+       char emails[MAX_EMAILS][MAX_EMAIL_LEN];
+       int j;
+       char *realname = get_real_name();
+       char *style = options_get_str("address_style");
+
+       fprintf(out,
+               "-----------------------------------------\n%s's address book\n"
+               "-----------------------------------------\n\n\n",
+               realname);
+       free(realname);
+
+       db_enumerate_items(e) {
+               fprintf(out,
+                       "-----------------------------------------\n\n");
+               fprintf(out, "%s", database[e.item][NAME]);
+               if (database[e.item][NICK])
+                       fprintf(out, "\n(%s)", database[e.item][NICK]);
+               fprintf(out, "\n");
+
+               if (*database[e.item][EMAIL]) {
+                       fprintf(out, "\n");
+                       split_emailstr(e.item, emails);
+                       for (j = 0; j < MAX_EMAILS; j++)
+                               if (*emails[j])
+                                       fprintf(out, "%s\n", emails[j]);
+               }
+               /* Print address */
+               if (database[e.item][ADDRESS]) {
+                       if (!safe_strcmp(style, "us"))  /* US like */
+                               text_write_address_us(out, e.item);
+                       else if (!safe_strcmp(style, "uk"))     /* UK like */
+                               text_write_address_uk(out, e.item);
+                       else    /* EU like */
+                               text_write_address_eu(out, e.item);
+
+                       fprintf(out, "\n");
+               }
+
+               if ((database[e.item][PHONE]) ||
+                       (database[e.item][WORKPHONE]) ||
+                       (database[e.item][FAX]) ||
+                       (database[e.item][MOBILEPHONE])) {
+                       fprintf(out, "\n");
+                       for (j = PHONE; j <= MOBILEPHONE; j++)
+                               if (database[e.item][j])
+                                       fprintf(out, "%s: %s\n",
+                                               abook_fields[j].name,
+                                               database[e.item][j]);
+               }
+
+               if (database[e.item][URL])
+                       fprintf(out, "\n%s\n", database[e.item][URL]);
+               if (database[e.item][NOTES])
+                       fprintf(out, "\n%s\n", database[e.item][NOTES]);
+
+               fprintf(out, "\n");
+       }
+
+       fprintf(out, "-----------------------------------------\n");
+
+       return 0;
+}
+
+/*
+ * end of printable export filter
+ */
+
+/*
+ * elm alias export filter
+ */
+
+static int
+elm_alias_export(FILE *out, struct db_enumerator e)
+{
+       char email[MAX_EMAIL_LEN];
+       char *alias = NULL;
+
+       db_enumerate_items(e) {
+               alias = mutt_alias_genalias(e.item);
+               get_first_email(email, e.item);
+               fprintf(out, "%s = %s = %s\n",
+                               alias,
+                               database[e.item][NAME],
+                               email);
+               my_free(alias);
+       }
+
+       return 0;
+}
+
+/*
+ * end of elm alias export filter
+ */
+
+
+/*
+ * Spruce export filter
+ */
+
+static int
+spruce_export_database (FILE *out, struct db_enumerator e)
+{
+       char email[MAX_EMAIL_LEN];
+
+       fprintf (out, "# This is a generated file made by abook for the Spruce e-mail client.\n\n");
+
+       db_enumerate_items(e) {
+               if(strcmp (safe_str(database[e.item][EMAIL]), "")) {
+                       get_first_email(email, e.item);
+                       fprintf(out, "# Address %d\nName: %s\nEmail: %s\nMemo: %s\n\n",
+                                       e.item,
+                                       database[e.item][NAME],
+                                       email,
+                                       safe_str(database[e.item][NOTES])
+                                       );
+               }
+       }
+
+       fprintf (out, "# End of address book file.\n");
+
+       return 0;
+}
+
+/*
+ * end of Spruce export filter
+ */
+
diff --git a/filter.h b/filter.h
new file mode 100644 (file)
index 0000000..a1ee168
--- /dev/null
+++ b/filter.h
@@ -0,0 +1,32 @@
+#ifndef _FILTER_H
+#define _FILTER_H
+
+#include "database.h"
+
+#define                FILTNAME_LEN    6
+
+
+struct abook_output_filter {
+       char filtname[FILTNAME_LEN];
+       char *desc;
+       int (*func) (FILE *handle, struct db_enumerator e);
+};
+
+struct abook_input_filter {
+       char filtname[FILTNAME_LEN];
+       char *desc;
+       int (*func) (FILE *handle);
+};
+
+
+int            import_database();
+int             import(char filtname[FILTNAME_LEN], char *filename);
+
+int            export_database();
+int             export(char filtname[FILTNAME_LEN], char *filename);
+int            fexport(char filtname[FILTNAME_LEN], FILE *handle,
+               int enum_mode);
+
+void           print_filters();
+
+#endif
diff --git a/getname.c b/getname.c
new file mode 100644 (file)
index 0000000..41b8503
--- /dev/null
+++ b/getname.c
@@ -0,0 +1,355 @@
+
+/*
+ * This code was taken from hypermail http://www.hypermail.org/
+ *
+ * license: GNU GENERAL PUBLIC LICENSE, Version 2
+ *
+ * modified by Jaakko Heinonen <jheinonen@users.sourceforge.net>
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+/*#include "hypermail.h"*/
+#include "getname.h"
+/*#include "setup.h"*/
+
+/*extern char *set_domainaddr;*/
+const char *set_domainaddr = "";
+const int use_domainaddr = 0;
+
+#define NAMESTRLEN   80
+#define MAILSTRLEN   80
+
+#define NONAME      "(no name)"
+#define NOEMAIL     "(no email)"
+
+#ifndef FALSE
+#      define FALSE    0
+#endif
+
+#ifndef TRUE
+#      define TRUE     1
+#endif
+
+#define hm_strchr(X, XX) strchr(X, XX)
+#define strsav(X) ((X == NULL) ? strdup("") : strdup(X))
+
+/*const int set_iso2022jp = 0;*/
+
+void
+strcpymax(char *dest, const char *src, int n)
+{
+       int i;
+
+       if (n) {
+               n--;            /* decrease one to allow for the termination byte */
+               for (i = 0; *src && (i < n); i++)
+                       *dest++ = *src++;
+       }
+       *dest = 0;
+}
+
+static int
+blankstring(char *str)
+{
+       register char *cp;
+       for (cp = str; *cp; cp++) {
+               if (*cp != ' ' && *cp != '\t' && *cp != '\r'
+                   && *cp != '\n')
+                       return (0);
+       }
+       return (1);
+}
+
+#if 0
+char *
+spamify(char *input)
+{
+       /* we should replace the @-letter in the email
+          address */
+       int newlen = strlen(input) + 4;
+       char *atptr = strchr(input, '@');
+       if (atptr) {
+               char *newbuf = malloc(newlen);
+               int index = atptr - input;
+               /* copy the part before the @ */
+               memcpy(newbuf, input, index);
+               /* append _at_ */
+               memcpy(newbuf + index, "_at_", 4);
+               /* append the part after the @ */
+               strcpy(newbuf + index + 4, input + index + 1);
+               /* correct the pointer and free the old */
+               free(input);
+               return newbuf;
+       }
+       /* weird email, bail out */
+       return input;
+}
+#endif
+
+/*
+** Grabs the name and email address from a From: header.
+** This could get tricky; I've tried to keep it simple.
+** Should be able to handle all the addresses below:
+**
+**   From: user                   [no @]
+**   From: kent (Kent Landfield)  [no @ - with comment]
+**   From: <user@node.domain>     [no text name, use email as text name]
+**   From: Kent Landfield <kent>  [text name but no @]
+**   From: (kent)                 [comment - no email address]
+**   From: "" <kent>              [email address but null comment]
+**   From:                        [blank From: line]
+**   From: uu.net!kent            [uucp addresses - no comment]
+**   From: uu.net!kent (kent)     [uucp addresses - with comment]
+**   From: "(Joe Bloggs)" <joe@anorg.com> 
+**   From: "Roy T. Fielding" <fielding@kiwi.ics.uci.edu>
+**   From: kent@localhost
+**   From: kent@uu.net (Kent Landfield)
+**   From: (George Burgyan) <gburgyan@cybercon.com>
+**   From: <gburgyan@cybercon.com> (George Burgyan) 
+**   From:              Kent B. Landfield <kent@landfield.com>
+**   From:      IN%"fekete+reply@c2.net" 26-JAN-1997 13:28:55.36
+**   From:      IN%"vicric@panix.com"  "Vicki Richman" 13-AUG-1996 10:54:33.38
+**   From:      US2RMC::"lwv26@cas.org" "Larry W. Virden, x2487" 22-OCT-1994 09:44:21.44
+**   From:          Mail Delivery Subsystem <postmaster@igc.apc.org>
+**   From:          Self <ehasbrouck>
+**   From:         adam@eden.apana.org.au (Adam Frey)
+**   From:        faqserv@penguin-lust.mit.edu
+**   From:    nc0548@freebsd.netcom.com (Mark Hittinger)
+**   From: "- Pam Greene, one of the *.answers moderators" <pgreene@MIT.EDU>
+**   From: "Felan shena Thoron'edras" <felan@netcom.com>
+**   From: David Muir Sharnoff <muir@idiom.com>
+**   From: A.J.Doherty@reading.ac.uk (Andy Doherty)
+**   From: Jordan Hubbard                        <jkh@vector.eikon.e-technik.tu-muenchen.de>
+**   From: ZXPAN%SLACVM.BITNET@MITVMA.MIT.EDU
+**   From: afs!piz!alf@uu5.psi.com (Alf the Poet)
+**   From: answers@cp.tn.tudelft.nl ("Moderator *.answers")
+**   From: mdw%merengue@merengue.oit.unc.edu (Matt Welsh)
+**   From: bgoffe@whale.st.usm.edu (William L. Goffe)
+**
+** This is an interesting new one (1998-11-26):
+** From: <name.hidden@era.ericsson.se>\9bName.Hidden@era.ericsson.se\9c
+*/
+
+void
+getname(char *line, char **namep, char **emailp)
+{
+       int i;
+       int len;
+       char *c;
+       int comment_fnd;
+
+       char email[MAILSTRLEN];
+       char name[NAMESTRLEN];
+
+       len = MAILSTRLEN - 1;
+       comment_fnd = 0;
+
+       /*
+        * Zero out data storage.
+        */
+       memset(email, 0, MAILSTRLEN);
+       memset(name, 0, NAMESTRLEN);
+
+       *namep = NULL;
+       *emailp = NULL;
+
+       /* EMail Processing First:
+          ** First, is there an '@' sign we can use as an anchor ?
+        */
+       if ((c = hm_strchr(line, '@')) == NULL) {
+               /* 
+                  ** No '@' sign here so ...
+                */
+               if (strchr(line, '(')) {        /* From: bob (The Big Guy) */
+                       c = strchr(line, ':') + 1;
+                       while (*c == ' ' || *c == '\t')
+                               c++;
+                       for (i = 0; *c && *c != '(' && *c != ' ' &&
+                            *c != '\t' && *c != '\n' && i < len; c++)
+                               email[i++] = *c;
+                       email[i] = '\0';
+               } else if ((c = strchr(line, '<'))) {   /* From: <kent> */
+                       c++;
+                       for (i = 0; *c && *c != '>' && *c != ' ' &&
+                            *c != '\t' && *c != '\n' && i < len; c++)
+                               email[i++] = *c;
+                       email[i] = '\0';
+               } else {
+                       /* 
+                        *    - check to see if the From: line is blank, (taken care of)
+                        *    - check if From: uu.net!kent formatted line
+                        *    - check if "From: kent" formatted line
+                        */
+                       c = strchr(line, ':') + 1;
+                       while (*c == ' ' || *c == '\t')
+                               c++;
+                       for (i = 0; *c && *c != ' ' && *c != '\t' &&
+                            *c != '\n' && *c != ',' && i < len; c++)
+                               email[i++] = *c;
+                       email[i] = '\0';
+
+               }
+
+               if (email[0] == '\0')   /* Was it a junk From line ? */
+                       strcpymax(email, NOEMAIL, MAILSTRLEN);
+
+               else if (use_domainaddr) {
+                       /*
+                        * check if site domainizes addresses 
+                        * but don't modify uucp addresses
+                        */
+                       if ((c = strchr(email, '!')) == NULL) {
+                               strcat(email, "@");
+                               strcat(email, set_domainaddr);
+                       }
+               }
+       } else {
+               while (*c != ' ' && *c != '\t' && *c != '<' && *c != '"' &&
+                      *c != ':')
+                       c--;
+               c++;
+               for (i = 0; *c && *c != '>' && *c != ' ' && *c != '\t' &&
+                    *c != '"' && *c != '\n' && *c != ']' && *c != ',' &&
+                    i < len; c++)
+                       email[i++] = *c;
+               email[i] = '\0';
+       }
+
+       /*
+        * NAME Processing - Boy are there a bunch of funky formats here.
+        *                   No promises... I'll do my best. Let me know
+        *                   what I missed...
+        */
+
+       if (strchr(line, '<')) {
+               c = strchr(line, ':') + 1;
+               while (*c == ' ' || *c == '\t')
+                       c++;
+
+               /* if a comment then just look for the end point */
+
+               if (*c == '\"') {
+                       int rmparen = 0;
+
+                       ++c;
+                       if (*c == '(') {
+                               ++c;
+                               rmparen = 1;
+                       }
+                       for (i = 0, len = NAMESTRLEN - 1;
+                            *c && *c != '\"' && *c != '\n' && i < len;
+                            c++)
+                               name[i++] = *c;
+
+                       if (rmparen && name[(i - 1)] == ')')
+                               --i;    /* get rid of "(name-comment)" parens */
+
+                       comment_fnd = 1;
+               } else if (hm_strchr(line, '(')) {
+                       c = hm_strchr(line, '(') + 1;
+                       if (*c == '"')  /* is there a comment in the comment ? */
+                               c++;
+               } else if (*c == '<') { /* Comment may be on the end */
+                       /* From: <bill@celestial.com> Bill Campbell */
+                       c = strchr(line, '>') + 1;
+                       for (i = 0, len = NAMESTRLEN - 1;
+                            *c && *c != '\n' && i < len; c++)
+                               name[i++] = *c;
+
+                       comment_fnd = 1;
+               }
+       } else if (strchr(line, '(')) {
+               c = strchr(line, '(');
+               c++;
+               if (*c == '"')  /* is there a comment in the comment ? */
+                       c++;
+               while (*c == ' ' || *c == '\t')
+                       c++;
+       } else if (strchr(line, '[')) {
+               c = strchr(line, ':') + 1;
+               while (*c == ' ' || *c == '\t')
+                       c++;
+
+               for (i = 0, len = NAMESTRLEN - 1;
+                    *c && *c != '\"' && *c != '[' && *c != '\n'
+                    && i < len; c++)
+                       name[i++] = *c;
+
+               name[--i] = '\0';
+               comment_fnd = 1;
+       } else {
+               /*
+                * Is there an email address available 
+                * that we can use for the name ?
+                */
+               if (!strcmp(email, NOEMAIL))    /* No */
+                       strcpymax(name, NONAME, NAMESTRLEN);
+               else {
+                       c = email + strlen(email) - 1;
+                       while (isspace((unsigned char) *c))
+                               *c-- = '\0';
+                       strcpymax(name, email, NAMESTRLEN);     /* Yes */
+               }
+               *namep = strsav(name);
+               *emailp = strsav(email);
+               return;
+       }
+
+       if (!comment_fnd) {
+               /*int in_ascii = TRUE, esclen = 0; */
+               for (i = 0, len = NAMESTRLEN - 1;
+                    *c && *c != '<' && *c != '\"' && *c != ')'
+                    && *c != '(' && *c != '\n' && i < len; c++) {
+                       /*if (set_iso2022jp) {
+                          iso2022_state(c, &in_ascii, &esclen);
+                          if (esclen) {
+                          for (; esclen; esclen--, c++) name[i++] = *c;
+                          for (; in_ascii == FALSE && i < len;
+                          c++, iso2022_state(c, &in_ascii, &esclen)) {
+                          name[i++] = *c;
+                          }
+                          c--;
+                          } else {
+                          name[i++] = *c;
+                          }
+                          } else { */
+                       name[i++] = *c;
+                       /*} */
+               }
+       }
+
+       if (i > 0 && name[i - 1] == ' ' && (*c == '<' || *c == '('))
+               name[--i] = '\0';
+       else
+               name[i] = '\0';
+
+       /*
+        * Is the name string blank ? If so then 
+        * force it to get filled with something.
+        */
+       if (blankstring(name))
+               name[0] = '\0';
+
+       /* Bailing and taking the easy way out... */
+
+       if (name[0] == '\0') {
+               if (email[0] == '\0')
+                       strcpymax(name, NONAME, NAMESTRLEN);
+               else
+                       strcpymax(name, email, NAMESTRLEN);
+       }
+
+       /* 
+        * need to strip spaces off the end of 
+        * the email and name strings 
+        */
+
+       c = email + (strlen(email) - 1);
+       while (c > email && isspace((unsigned char) *c))
+               *c-- = '\0';
+
+       *namep = strsav(name);
+       *emailp = strsav(email);
+}
diff --git a/getname.h b/getname.h
new file mode 100644 (file)
index 0000000..283a67a
--- /dev/null
+++ b/getname.h
@@ -0,0 +1,9 @@
+#ifndef _GETNAME_H
+#define _GETNAME_H
+
+void getname(char *, char **, char **);
+#if 0
+char *spamify(char *input);
+#endif
+
+#endif
diff --git a/help.h b/help.h
new file mode 100644 (file)
index 0000000..abb040e
--- /dev/null
+++ b/help.h
@@ -0,0 +1,69 @@
+#ifndef _HELP_H
+#define _HELP_H
+
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+
+static char *mainhelp[] = {
+
+"      ?               help\n",
+"      q               quit\n",
+"      Q               quit and print selected item(s) to stderr\n",
+"      ^L              refresh screen\n",
+"\n",
+"      arrows / j,k    scroll list\n",
+"      enter           view/edit item\n",
+"      a               add item\n",
+"      r / del         remove selected items\n",
+"\n",
+"      space           select item\n",
+"      +               select all\n",
+"      -               select none\n",
+"      *               invert selection\n",
+"\n",
+"      w               write database to disk\n",
+"      l               read database from disk\n",
+"      C               clear whole database\n",
+"      i               import database\n",
+"      e               export database\n",
+"      p               print database\n",
+"      o               open database\n",
+"\n",
+"      s               sort database\n",
+"      S               \"surname sort\"\n",
+"\n",
+"      /               find\n",
+"      \\              find next\n",
+"\n",
+"      A               move current item up\n",
+"      Z               move current item down\n",
+"\n",
+"      m               send mail with mutt\n",
+"      u               view URL with www browser\n",
+NULL
+
+};
+
+static char *editorhelp[] = {
+
+"\n",
+"      a,c,p,o / left,right    change tab\n",
+"\n",
+"      1 - 5                   edit fields\n",
+"\n",
+"      k or <                  previous item\n",
+"      j or >                  next item\n",
+"\n",
+"      r                       roll e-mail addresses\n",
+"\n",
+"      u                       undo\n",
+"\n",
+"      m                       send mail with mutt\n",
+"      v                       view url with WWW browser\n",
+"\n",
+NULL
+
+};
+
+#endif
diff --git a/install-sh b/install-sh
new file mode 100755 (executable)
index 0000000..e843669
--- /dev/null
@@ -0,0 +1,250 @@
+#!/bin/sh
+#
+# install - install a program, script, or datafile
+# This comes from X11R5 (mit/util/scripts/install.sh).
+#
+# Copyright 1991 by the Massachusetts Institute of Technology
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of M.I.T. not be used in advertising or
+# publicity pertaining to distribution of the software without specific,
+# written prior permission.  M.I.T. makes no representations about the
+# suitability of this software for any purpose.  It is provided "as is"
+# without express or implied warranty.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.  It can only install one file at a time, a restriction
+# shared with many OS's install programs.
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+transformbasename=""
+transform_arg=""
+instcmd="$mvprog"
+chmodcmd="$chmodprog 0755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+dir_arg=""
+
+while [ x"$1" != x ]; do
+    case $1 in
+       -c) instcmd="$cpprog"
+           shift
+           continue;;
+
+       -d) dir_arg=true
+           shift
+           continue;;
+
+       -m) chmodcmd="$chmodprog $2"
+           shift
+           shift
+           continue;;
+
+       -o) chowncmd="$chownprog $2"
+           shift
+           shift
+           continue;;
+
+       -g) chgrpcmd="$chgrpprog $2"
+           shift
+           shift
+           continue;;
+
+       -s) stripcmd="$stripprog"
+           shift
+           continue;;
+
+       -t=*) transformarg=`echo $1 | sed 's/-t=//'`
+           shift
+           continue;;
+
+       -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
+           shift
+           continue;;
+
+       *)  if [ x"$src" = x ]
+           then
+               src=$1
+           else
+               # this colon is to work around a 386BSD /bin/sh bug
+               :
+               dst=$1
+           fi
+           shift
+           continue;;
+    esac
+done
+
+if [ x"$src" = x ]
+then
+       echo "install:  no input file specified"
+       exit 1
+else
+       true
+fi
+
+if [ x"$dir_arg" != x ]; then
+       dst=$src
+       src=""
+       
+       if [ -d $dst ]; then
+               instcmd=:
+       else
+               instcmd=mkdir
+       fi
+else
+
+# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+# might cause directories to be created, which would be especially bad 
+# if $src (and thus $dsttmp) contains '*'.
+
+       if [ -f $src -o -d $src ]
+       then
+               true
+       else
+               echo "install:  $src does not exist"
+               exit 1
+       fi
+       
+       if [ x"$dst" = x ]
+       then
+               echo "install:  no destination specified"
+               exit 1
+       else
+               true
+       fi
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+       if [ -d $dst ]
+       then
+               dst="$dst"/`basename $src`
+       else
+               true
+       fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+#  this part is taken from Noah Friedman's mkinstalldirs script
+
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='   
+'
+IFS="${IFS-${defaultIFS}}"
+
+oIFS="${IFS}"
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS="${oIFS}"
+
+pathcomp=''
+
+while [ $# -ne 0 ] ; do
+       pathcomp="${pathcomp}${1}"
+       shift
+
+       if [ ! -d "${pathcomp}" ] ;
+        then
+               $mkdirprog "${pathcomp}"
+       else
+               true
+       fi
+
+       pathcomp="${pathcomp}/"
+done
+fi
+
+if [ x"$dir_arg" != x ]
+then
+       $doit $instcmd $dst &&
+
+       if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
+       if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
+       if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
+       if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
+else
+
+# If we're going to rename the final executable, determine the name now.
+
+       if [ x"$transformarg" = x ] 
+       then
+               dstfile=`basename $dst`
+       else
+               dstfile=`basename $dst $transformbasename | 
+                       sed $transformarg`$transformbasename
+       fi
+
+# don't allow the sed command to completely eliminate the filename
+
+       if [ x"$dstfile" = x ] 
+       then
+               dstfile=`basename $dst`
+       else
+               true
+       fi
+
+# Make a temp file name in the proper directory.
+
+       dsttmp=$dstdir/#inst.$$#
+
+# Move or copy the file name to the temp name
+
+       $doit $instcmd $src $dsttmp &&
+
+       trap "rm -f ${dsttmp}" 0 &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing.  If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+       if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
+       if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
+       if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
+       if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
+
+# Now rename the file to the real destination.
+
+       $doit $rmcmd -f $dstdir/$dstfile &&
+       $doit $mvcmd $dsttmp $dstdir/$dstfile 
+
+fi &&
+
+
+exit 0
diff --git a/ldif.c b/ldif.c
new file mode 100644 (file)
index 0000000..46230ad
--- /dev/null
+++ b/ldif.c
@@ -0,0 +1,342 @@
+
+/*
+ * adapted to use with abook by JH <jheinonen@users.sourceforge.net>
+ */
+
+/*
+ *
+ * Copyright (c) 1992-1996 Regents of the University of Michigan.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of Michigan at Ann Arbor. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include "ldif.h"
+
+#define ISSPACE(c) isspace((unsigned char)c)
+
+#define LDAP_DEBUG_PARSE       0x800
+#define LDAP_DEBUG_ANY         0xffff
+#define LDIF_LINE_WIDTH                76      /* maximum length of LDIF lines */
+#define LDIF_BASE64_LEN(vlen)  (((vlen) * 4 / 3 ) + 3)
+
+#define LDIF_SIZE_NEEDED(tlen,vlen) \
+       ((tlen) + 4 + LDIF_BASE64_LEN(vlen) \
+     + ((LDIF_BASE64_LEN(vlen) + tlen + 3) / LDIF_LINE_WIDTH * 2 ))
+
+
+#define Debug( level, fmt, arg1, arg2, arg3 )
+
+#define RIGHT2                 0x03
+#define RIGHT4                 0x0f
+#define CONTINUED_LINE_MARKER  '\001'
+
+static char nib2b64[0x40f] =
+        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static unsigned char b642nib[0x80] = {
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f,
+       0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
+       0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+       0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
+       0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
+       0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
+       0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
+       0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
+       0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+
+/*
+ * str_parse_line - takes a line of the form "type:[:] value" and splits it
+ * into components "type" and "value".  if a double colon separates type from
+ * value, then value is encoded in base 64, and parse_line un-decodes it
+ * (in place) before returning.
+ */
+
+int
+str_parse_line(
+    char       *line,
+    char       **type,
+    char       **value,
+    int                *vlen
+)
+{
+       char    *p, *s, *d, *byte, *stop;
+       char    nib;
+       int     i, b64;
+
+       /* skip any leading space */
+       while ( ISSPACE( *line ) ) {
+               line++;
+       }
+       *type = line;
+
+       for ( s = line; *s && *s != ':'; s++ )
+               ;       /* NULL */
+       if ( *s == '\0' ) {
+               Debug( LDAP_DEBUG_PARSE, "parse_line missing ':'\n", 0, 0, 0 );
+               return( -1 );
+       }
+
+       /* trim any space between type and : */
+       for ( p = s - 1; p > line && ISSPACE( *p ); p-- ) {
+               *p = '\0';
+       }
+       *s++ = '\0';
+
+       /* check for double : - indicates base 64 encoded value */
+       if ( *s == ':' ) {
+               s++;
+               b64 = 1;
+
+       /* single : - normally encoded value */
+       } else {
+               b64 = 0;
+       }
+
+       /* skip space between : and value */
+       while ( ISSPACE( *s ) ) {
+               s++;
+       }
+
+       /* if no value is present, error out */
+       if ( *s == '\0' ) {
+               Debug( LDAP_DEBUG_PARSE, "parse_line missing value\n", 0,0,0 );
+               return( -1 );
+       }
+
+       /* check for continued line markers that should be deleted */
+       for ( p = s, d = s; *p; p++ ) {
+               if ( *p != CONTINUED_LINE_MARKER )
+                       *d++ = *p;
+       }
+       *d = '\0';
+
+       *value = s;
+       if ( b64 ) {
+               stop = strchr( s, '\0' );
+               byte = s;
+               for ( p = s, *vlen = 0; p < stop; p += 4, *vlen += 3 ) {
+                       for ( i = 0; i < 3; i++ ) {
+                               if ( p[i] != '=' && (p[i] & 0x80 ||
+                                   b642nib[ p[i] & 0x7f ] > 0x3f) ) {
+                                       Debug( LDAP_DEBUG_ANY,
+                                   "invalid base 64 encoding char (%c) 0x%x\n",
+                                           p[i], p[i], 0 );
+                                       return( -1 );
+                               }
+                       }
+
+                       /* first digit */
+                       nib = b642nib[ p[0] & 0x7f ];
+                       byte[0] = nib << 2;
+                       /* second digit */
+                       nib = b642nib[ p[1] & 0x7f ];
+                       byte[0] |= nib >> 4;
+                       byte[1] = (nib & RIGHT4) << 4;
+                       /* third digit */
+                       if ( p[2] == '=' ) {
+                               *vlen += 1;
+                               break;
+                       }
+                       nib = b642nib[ p[2] & 0x7f ];
+                       byte[1] |= nib >> 2;
+                       byte[2] = (nib & RIGHT2) << 6;
+                       /* fourth digit */
+                       if ( p[3] == '=' ) {
+                               *vlen += 2;
+                               break;
+                       }
+                       nib = b642nib[ p[3] & 0x7f ];
+                       byte[2] |= nib;
+
+                       byte += 3;
+               }
+               s[ *vlen ] = '\0';
+       } else {
+               *vlen = (int) (d - s);
+       }
+
+       return( 0 );
+}
+
+#if 0
+
+/*
+ * str_getline - return the next "line" (minus newline) of input from a
+ * string buffer of lines separated by newlines, terminated by \n\n
+ * or \0.  this routine handles continued lines, bundling them into
+ * a single big line before returning.  if a line begins with a white
+ * space character, it is a continuation of the previous line. the white
+ * space character (nb: only one char), and preceeding newline are changed
+ * into CONTINUED_LINE_MARKER chars, to be deleted later by the
+ * str_parse_line() routine above.
+ *
+ * it takes a pointer to a pointer to the buffer on the first call,
+ * which it updates and must be supplied on subsequent calls.
+ */
+
+char *
+str_getline( char **next )
+{
+       char    *l;
+       char    c;
+
+       if ( *next == NULL || **next == '\n' || **next == '\0' ) {
+               return( NULL );
+       }
+
+       l = *next;
+       while ( (*next = strchr( *next, '\n' )) != NULL ) {
+               c = *(*next + 1);
+               if ( ISSPACE( c ) && c != '\n' ) {
+                       **next = CONTINUED_LINE_MARKER;
+                       *(*next+1) = CONTINUED_LINE_MARKER;
+               } else {
+                       *(*next)++ = '\0';
+                       break;
+               }
+               (*next)++;
+       }
+
+       return( l );
+}
+
+#endif
+
+void
+put_type_and_value( char **out, char *t, char *val, int vlen )
+{
+       unsigned char   *byte, *p, *stop;
+       unsigned char   buf[3];
+       unsigned long   bits;
+       char            *save;
+       int             i, b64, pad, len, savelen;
+       len = 0;
+
+       /* put the type + ": " */
+       for ( p = (unsigned char *) t; *p; p++, len++ ) {
+               *(*out)++ = *p;
+       }
+       *(*out)++ = ':';
+       len++;
+       save = *out;
+       savelen = len;
+       *(*out)++ = ' ';
+       b64 = 0;
+
+       stop = (unsigned char *) (val + vlen);
+       if ( isascii( val[0] ) && (ISSPACE( val[0] ) || val[0] == ':') ) {
+               b64 = 1;
+       } else {
+               for ( byte = (unsigned char *) val; byte < stop;
+                   byte++, len++ ) {
+                       if ( !isascii( *byte ) || !isprint( *byte ) ) {
+                               b64 = 1;
+                               break;
+                       }
+                       if ( len > LDIF_LINE_WIDTH ) {
+                               *(*out)++ = '\n';
+                               *(*out)++ = ' ';
+                               len = 1;
+                       }
+                       *(*out)++ = *byte;
+               }
+       }
+       if ( b64 ) {
+               *out = save;
+               *(*out)++ = ':';
+               *(*out)++ = ' ';
+               len = savelen + 2;
+               /* convert to base 64 (3 bytes => 4 base 64 digits) */
+               for ( byte = (unsigned char *) val; byte < stop - 2;
+                   byte += 3 ) {
+                       bits = (byte[0] & 0xff) << 16;
+                       bits |= (byte[1] & 0xff) << 8;
+                       bits |= (byte[2] & 0xff);
+
+                       for ( i = 0; i < 4; i++, len++, bits <<= 6 ) {
+                               if ( len > LDIF_LINE_WIDTH ) {
+                                       *(*out)++ = '\n';
+                                       *(*out)++ = ' ';
+                                       len = 1;
+                               }
+
+                               /* get b64 digit from high order 6 bits */
+                               *(*out)++ = nib2b64[ (bits & 0xfc0000L) >> 18 ];
+                       }
+               }
+
+               /* add padding if necessary */
+               if ( byte < stop ) {
+                       for ( i = 0; byte + i < stop; i++ ) {
+                               buf[i] = byte[i];
+                       }
+                       for ( pad = 0; i < 3; i++, pad++ ) {
+                               buf[i] = '\0';
+                       }
+                       byte = buf;
+                       bits = (byte[0] & 0xff) << 16;
+                       bits |= (byte[1] & 0xff) << 8;
+                       bits |= (byte[2] & 0xff);
+
+                       for ( i = 0; i < 4; i++, len++, bits <<= 6 ) {
+                               if ( len > LDIF_LINE_WIDTH ) {
+                                       *(*out)++ = '\n';
+                                       *(*out)++ = ' ';
+                                       len = 1;
+                               }
+
+                               /* get b64 digit from low order 6 bits */
+                               *(*out)++ = nib2b64[ (bits & 0xfc0000L) >> 18 ];
+                       }
+
+                       for ( ; pad > 0; pad-- ) {
+                               *(*out - pad) = '=';
+                       }
+               }
+       }
+       *(*out)++ = '\n';
+}
+
+
+char *
+ldif_type_and_value( char *type, char *val, int vlen )
+/*
+ * return malloc'd, zero-terminated LDIF line
+ */
+{
+    char       *buf, *p;
+    int                tlen;
+
+    tlen = strlen( type );
+    if (( buf = (char *)malloc( LDIF_SIZE_NEEDED( tlen, vlen ) + 1 )) !=
+           NULL ) {
+    }
+
+    p = buf;
+    put_type_and_value( &p, type, val, vlen );
+    *p = '\0';
+
+    return( buf );
+}
+
diff --git a/ldif.h b/ldif.h
new file mode 100644 (file)
index 0000000..1672cfb
--- /dev/null
+++ b/ldif.h
@@ -0,0 +1,16 @@
+#ifndef _LDIF_H
+#define _LDIF_H
+
+
+/*
+ * prototypes
+ */
+
+int            str_parse_line(char        *line, char        **type,
+               char        **value, int         *vlen);
+char           *str_getline( char **next );
+void           put_type_and_value( char **out, char *t, char *val, int vlen );
+char           *ldif_type_and_value( char *type, char *val, int vlen );
+
+
+#endif
diff --git a/list.c b/list.c
new file mode 100644 (file)
index 0000000..7d5536c
--- /dev/null
+++ b/list.c
@@ -0,0 +1,345 @@
+
+/*
+ * $Id: list.c,v 1.15 2002/01/29 11:58:13 jheinonen Exp $
+ *
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "abook.h"
+#include <assert.h>
+#include "ui.h"
+#include "database.h"
+#include "edit.h"
+#include "list.h"
+#include "misc.h"
+#include "options.h"
+
+#define MIN_EXTRA_COLUMN       ADDRESS /* 2 */
+#define MAX_EXTRA_COLUMN       LAST_FIELD
+
+int curitem = -1;
+int first_list_item = -1;
+char *selected = NULL;
+
+int extra_column = -1;
+int extra_alternative = -1;
+
+extern int items;
+extern list_item *database;
+extern struct abook_field abook_fields[];
+
+WINDOW *list = NULL;
+
+static int
+init_extra_field(char *option_name)
+{
+       int i, ret = -1;
+       char *option_str;
+
+       assert(option_name != NULL);
+       
+       option_str = options_get_str(option_name);
+
+       if(option_str && *option_str) {
+               for(i = 0; i < ITEM_FIELDS; i++) {
+                       if(!strcasecmp(option_str, abook_fields[i].key)) {
+                               ret = i;
+                               break;
+                       }
+               }
+               if(ret < MIN_EXTRA_COLUMN || ret > MAX_EXTRA_COLUMN) {
+                       ret = -1;
+               }
+       }
+
+       return ret;
+}
+
+void
+init_list()
+{
+       list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0);
+       scrollok(list, TRUE);
+
+       /*
+        * init extra_column and extra alternative
+        */
+
+       extra_column = init_extra_field("extra_column");
+       extra_alternative = init_extra_field("extra_alternative");
+}
+
+void
+close_list()
+{
+       delwin(list);
+       list = NULL;
+}
+
+void
+refresh_list()
+{
+       int i, line;
+       
+       werase(list);
+
+       ui_print_number_of_items();
+       
+       if( items < 1 ) {
+               refresh();
+               wrefresh(list);
+               return;
+       }
+       
+       if(curitem < 0)
+               curitem = 0;
+
+       if(first_list_item < 0)
+               first_list_item = 0;
+
+       if(curitem < first_list_item)
+               first_list_item = curitem;
+       else if(curitem > LAST_LIST_ITEM)
+               first_list_item = max(curitem - LIST_LINES + 1, 0);
+
+        for( line = 0, i = first_list_item ; i <= LAST_LIST_ITEM && i < items;
+                       line++, i++ ) {
+
+               print_list_line(i, line, i == curitem);
+        }
+
+        wrefresh(list);
+}
+
+void
+print_list_line(int i, int line, int highlight)
+{
+       int extra = extra_column;
+       char tmp[MAX_EMAILSTR_LEN];
+       int real_emaillen = (extra_column > 0 || extra_alternative > 0) ?
+               EMAILLEN : COLS - EMAILPOS;
+
+       scrollok(list, FALSE);
+       if(highlight)
+               highlight_line(list, line);
+
+       if( selected[i] )
+               mvwaddch(list, line, 0, '*' );
+       
+       mvwaddnstr(list, line, NAMEPOS, database[i][NAME], NAMELEN);
+       if( options_get_int( "show_all_emails"  ) )
+               mvwaddnstr(list, line, EMAILPOS, database[i][EMAIL],
+                               real_emaillen);
+       else {
+               get_first_email(tmp, i);
+               mvwaddnstr(list, line, EMAILPOS, tmp, real_emaillen);
+       }
+
+       if(extra < 0 || !database[i][extra])
+               extra = extra_alternative;
+       if(extra >= 0)
+               mvwaddnstr(list, line, EXTRAPOS,
+                               safe_str(database[i][extra]),
+                               EXTRALEN);
+
+       scrollok(list, TRUE);
+       if(highlight)
+               wstandend(list);
+}
+       
+
+void
+list_headerline()
+{
+#ifdef A_BOLD
+       attrset(A_BOLD);
+#else
+       /* hmm, maybe something here */
+#endif
+       mvaddstr(2, NAMEPOS, abook_fields[NAME].name);
+       mvaddstr(2, EMAILPOS, abook_fields[EMAIL].name);
+       if(extra_column > 0)
+               mvaddnstr(2, EXTRAPOS, abook_fields[extra_column].name,
+                               COLS-EXTRAPOS);
+#ifdef A_BOLD
+       attrset(A_NORMAL);
+#endif
+}
+
+void
+scroll_up()
+{
+       if( curitem < 1 )
+               return;
+
+       curitem--;
+
+       refresh_list();
+}
+
+void
+scroll_down()
+{
+       if( curitem > items - 2 )
+               return;
+
+       curitem++;
+
+       refresh_list();
+}
+
+
+void
+page_up()
+{
+       if( curitem < 1 )
+               return;
+       
+       curitem = curitem == first_list_item ?
+               ((curitem -= LIST_LINES) < 0 ? 0 : curitem) : first_list_item;
+       
+       refresh_list();
+}
+
+void
+page_down()
+{
+       if( curitem > items - 2 )
+               return;
+
+       curitem = curitem == LAST_LIST_ITEM ?
+               ((curitem += LIST_LINES) > LAST_ITEM ? LAST_ITEM : curitem) :
+               min(LAST_LIST_ITEM, LAST_ITEM);
+
+       refresh_list();
+}
+
+
+void
+select_none()
+{
+        memset( selected, 0, items );
+}
+
+void
+select_all()
+{
+        memset( selected, 1, items );
+}
+
+void
+move_curitem(int direction)
+{
+        list_item tmp;
+
+        if( curitem < 0 || curitem > LAST_ITEM )
+                return;
+
+        itemcpy(tmp, database[curitem]);
+
+        switch(direction) {
+                case MOVE_ITEM_UP:
+                        if( curitem < 1 )
+                                return;
+                        itemcpy(database[curitem], database[curitem - 1]);
+                        itemcpy(database[curitem-1], tmp);
+                        scroll_up();
+                        break;
+
+                case MOVE_ITEM_DOWN:
+                        if( curitem >= LAST_ITEM )
+                                return;
+                        itemcpy(database[curitem], database[curitem + 1]);
+                        itemcpy(database[curitem+1], tmp);
+                        scroll_down();
+                        break;
+        }
+}
+
+void
+goto_home()
+{
+       if(items > 0)
+               curitem = 0;
+       
+       refresh_list();
+}
+
+void
+goto_end()
+{
+       if(items > 0)
+               curitem = LAST_ITEM;
+
+       refresh_list();
+}
+
+
+void
+highlight_line(WINDOW *win, int line)
+{
+       wstandout(win);
+
+       /*
+        * this is a tricky one
+        */
+#if 0
+/*#ifdef mvwchgat*/
+       mvwchgat(win, line, 0, -1,  A_STANDOUT, 0, NULL);
+#else
+       /*
+        * buggy function: FIXME
+        */
+       scrollok(win, FALSE);
+       {
+               int i;
+               wmove(win, line, 0);
+               for(i = 0; i < COLS; i++)
+                       waddch(win, ' ');
+       /*wattrset(win, 0);*/
+       }
+       scrollok(win, TRUE);
+#endif
+}
+
+int
+selected_items()
+{
+       int i, n = 0;
+
+       for(i = 0; i < items; i++)
+               if(selected[i])
+                       n++;
+
+       return n;
+}
+
+void
+invert_selection()
+{
+       int i;
+
+       if( items < 1 )
+               return;
+
+       for(i = 0; i < items; i++)
+               selected[i] = !selected[i];
+}
+
+int
+list_current_item()
+{
+       return curitem;
+}
+
+int
+list_is_empty()
+{
+       return items < 1;
+}
+
+       
diff --git a/list.h b/list.h
new file mode 100644 (file)
index 0000000..8a92dc6
--- /dev/null
+++ b/list.h
@@ -0,0 +1,48 @@
+#ifndef _LIST_H
+#define _LIST_H
+
+#include "ui.h"
+
+void           init_list();
+void           close_list();
+void            refresh_list();
+void           print_list_line(int i, int line, int highlight);
+void           list_headerline();
+void            scroll_up();
+void            scroll_down();
+void           page_up();
+void           page_down();
+void            select_none();
+void            select_all();
+void            move_curitem(int direction);
+void           goto_home();
+void           goto_end();
+void           highlight_line(WINDOW *win, int line);
+int            selected_items();
+void           invert_selection();
+int            list_current_item();
+int            list_is_empty();
+
+
+enum {
+       MOVE_ITEM_UP,
+       MOVE_ITEM_DOWN
+};
+
+#define LIST_TOP        3
+#define LIST_BOTTOM     (LINES-3)
+
+#define LIST_LINES     (LIST_BOTTOM-LIST_TOP)
+#define LIST_COLS      COLS
+
+#define NAMEPOS                2
+#define EMAILPOS        options_get_int("emailpos")
+#define EXTRAPOS       options_get_int("extrapos")
+
+#define NAMELEN                (EMAILPOS-NAMEPOS -1)
+#define EMAILLEN        (EXTRAPOS-EMAILPOS -1)
+#define EXTRALEN       (COLS-EXTRAPOS)
+
+#define LAST_LIST_ITEM ( first_list_item + LIST_LINES - 1 )
+
+#endif
diff --git a/misc.c b/misc.c
new file mode 100644 (file)
index 0000000..919e5db
--- /dev/null
+++ b/misc.c
@@ -0,0 +1,1084 @@
+
+/*
+ * $Id: misc.c,v 1.7 2001/12/19 20:20:55 jheinonen Exp $
+ *
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#define ABOOK_SRC      1
+/*#undef ABOOK_SRC*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <errno.h>
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+#include "misc.h"
+#ifdef ABOOK_SRC
+#      include "abook.h"
+#endif
+
+#ifndef DEBUG
+#      define NDEBUG   1
+#else
+#      undef NDEBUG
+#endif
+
+#include <assert.h>
+
+char *
+revstr(char *str)
+{
+       char *s, *s2;
+
+       assert(str != NULL);
+
+       s = s2 = strdup(str);
+
+       while( *str )
+               str++;
+
+       while( *s )
+               *--str = *s++;
+
+       free(s2);
+       return str;
+}
+
+char *
+strupper(char *str)
+{
+       char *tmp = str;
+
+       assert(str != NULL);
+
+       while( ( *str = toupper( *str ) ) )
+               str++;
+       
+       return tmp;
+}
+
+char *
+strlower(char *str)
+{
+       char *tmp = str;
+
+       assert(str != NULL);
+
+       while( ( *str = tolower ( *str ) ) )
+               str++;
+
+       return tmp;
+}
+
+char *
+strtrim(char *s)
+{
+       char *t, *tt;
+
+       assert(s != NULL);
+
+       for(t = s; ISSPACE(*t); t++);
+
+       memmove(s, t, strlen(t)+1);
+
+       for (tt = t = s; *t != '\0'; t++)
+               if(!ISSPACE(*t))
+                       tt = t+1;
+
+       *tt = '\0';
+
+       return s;
+}
+
+
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+
+/* varargs declarations: */
+
+#ifdef HAVE_STDARG_H
+#      define MY_VA_LOCAL_DECL   va_list ap
+#      define MY_VA_START(f)     va_start(ap, f)
+#      define MY_VA_SHIFT(v,t)   v = va_arg(ap, t)
+#      define MY_VA_END          va_end(ap)
+#else
+#      error HAVE_STDARG_H not defined
+#endif
+
+char *
+mkstr (const char *format, ... )
+{
+       MY_VA_LOCAL_DECL;
+       int size = 100;
+       char *buffer =
+#ifdef ABOOK_SRC
+               (char *) abook_malloc (size);
+#else
+               (char *) malloc (size);
+#endif
+       
+       assert(format != NULL);
+
+       for(;;) {
+               int n;
+               MY_VA_START(format);
+               n = vsnprintf (buffer, size,
+                               format, ap);
+               MY_VA_END;
+
+               if (n > -1 && n < size)
+                       return buffer;
+
+               if (n > -1)
+                       size = n + 1;
+               else
+                       size *= 2;
+               
+               buffer =
+#ifdef ABOOK_SRC
+                       (char *) abook_realloc (buffer, size);
+#else
+                       (char *) realloc (buffer, size);
+#endif
+       }
+}
+
+
+char*
+strconcat (const char *str, ...)
+{
+       int   l;
+       MY_VA_LOCAL_DECL;
+       char *s, *concat;
+
+       assert(str != NULL);
+
+       l = 1 + strlen (str);
+       MY_VA_START(str);
+       MY_VA_SHIFT(s, char*);
+       while (s) {
+               l += strlen (s);
+               MY_VA_SHIFT(s, char*);
+       }
+       MY_VA_END;
+       
+       concat = (char *)
+#ifdef ABOOK_SRC
+       abook_malloc(l);
+#else
+       malloc(l);
+#endif
+
+       strcpy (concat, str);
+       MY_VA_START(str);
+       MY_VA_SHIFT(s, char*);
+       while (s) {
+               strcat (concat, s);
+               MY_VA_SHIFT(s, char*);
+       }
+       MY_VA_END;
+
+       return concat;
+}
+
+
+int
+safe_strcmp(const char *s1, const char *s2)
+{
+       if (s1 == NULL && s2 == NULL) return 0;
+       if (s1 == NULL) return -1;
+       if (s2 == NULL) return 1;
+
+       return strcmp(s1, s2);
+}
+
+int
+safe_strcoll(const char *s1, const char *s2)
+{
+#ifdef HAVE_STRCOLL
+       if (s1 == NULL && s2 == NULL) return 0;
+       if (s1 == NULL) return -1;
+       if (s2 == NULL) return 1;
+
+       return strcoll(s1, s2);
+#else /* fall back to strcmp */
+       return safe_strcmp(s1, s2);
+#endif
+}
+
+char *
+my_getcwd()
+{
+       char *dir = NULL;
+       int size = 100;
+
+       if( (dir = malloc(size)) == NULL)
+               return NULL;
+       
+       while( getcwd(dir, size) == NULL && errno == ERANGE )
+               if( (dir = realloc(dir, size *=2)) == NULL)
+                       return NULL;
+
+       return dir;
+}
+
+#define INITIAL_SIZE   128
+#ifndef ABOOK_SRC
+#      define abook_malloc(X) malloc(X)
+#      define abook_realloc(X, XX) realloc(X, XX)
+#endif
+
+char *
+getaline(FILE *f)
+{
+       char *buf;              /* buffer for line */
+       size_t size;            /* size of buffer */
+       size_t inc;             /* how much to enlarge buffer */
+       size_t len;             /* # of chars stored into buf before '\0' */
+       char *p;
+       const size_t thres = 128; /* initial buffer size (most lines should
+                                    fit into this size, so think of this as
+                                    the "long line threshold").  */
+       const size_t mucho = 128; /* if there is at least this much wasted
+                                    space when the whole buffer has been
+                                    read, try to reclaim it.  Don't make
+                                    this too small, else there is too much
+                                    time wasted trying to reclaim a couple
+                                    of bytes.  */
+       const size_t mininc = 64; /* minimum number of bytes by which
+                                    to increase the allocated memory */
+
+       len = 0;
+       size = thres;
+       buf = (char *)abook_malloc(size);
+
+       while (fgets(buf+len, size-len, f) != NULL) {
+               len += strlen(buf+len);
+               if (len > 0 && buf[len-1] == '\n')
+                       break;          /* the whole line has been read */
+
+               for (inc = size, p = NULL; inc > mininc; inc /= 2)
+                       if ((p = abook_realloc(buf, size + inc)) != NULL)
+                               break;
+
+               size += inc;
+               buf = p;
+       }
+
+       if (len == 0) {
+               free(buf);
+               return NULL;    /* nothing read (eof or error) */
+       }
+
+       if (buf[len-1] == '\n') /* remove newline, if there */
+               buf[--len] = '\0';
+
+       if (size - len > mucho) { /* a plenitude of unused memory? */
+               p = abook_realloc(buf, len+1);
+               if (p != NULL) {
+                       buf = p;
+                       size = len+1;
+               }
+       }
+
+       return buf;
+}
+
+/**************************************************************
+ * Original:
+ * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
+ * A bombproof version of doprnt (dopr) included.
+ * Sigh.  This sort of thing is always nasty do deal with.  Note that
+ * the version here does not include floating point...
+ *
+ * snprintf() is used instead of sprintf() as it does limit checks
+ * for string length.  This covers a nasty loophole.
+ *
+ * The other functions are there to prevent NULL pointers from
+ * causing nast effects.
+ *
+ * More Recently:
+ *  Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43
+ *  This was ugly.  It is still ugly.  I opted out of floating point
+ *  numbers, but the formatter understands just about everything
+ *  from the normal C string format, at least as far as I can tell from
+ *  the Solaris 2.5 printf(3S) man page.
+ *
+ *  Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1
+ *    Ok, added some minimal floating point support, which means this
+ *    probably requires libm on most operating systems.  Don't yet
+ *    support the exponent (e,E) and sigfig (g,G).  Also, fmtint()
+ *    was pretty badly broken, it just wasn't being exercised in ways
+ *    which showed it, so that's been fixed.  Also, formated the code
+ *    to mutt conventions, and removed dead code left over from the
+ *    original.  Also, there is now a builtin-test, just compile with:
+ *           gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
+ *    and run snprintf for results.
+ * 
+ *  Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i
+ *    The PGP code was using unsigned hexadecimal formats. 
+ *    Unfortunately, unsigned formats simply didn't work.
+ *
+ *  Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8
+ *    The original code assumed that both snprintf() and vsnprintf() were
+ *    missing.  Some systems only have snprintf() but not vsnprintf(), so
+ *    the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
+ *
+ **************************************************************/
+
+#include "config.h"
+
+#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
+
+#include <string.h>
+# include <ctype.h>
+#include <sys/types.h>
+
+/* Define this as a fall through, HAVE_STDARG_H is probably already set */
+
+#if !defined(HAVE_STDARG_H) && !defined(HAVE_VARARGS_H)
+#      define HAVE_VARARGS_H   1
+#endif
+
+/* varargs declarations: */
+
+#if defined(HAVE_STDARG_H)
+/*# include <stdarg.h>*/
+# define HAVE_STDARGS    /* let's hope that works everywhere (mj) */
+# define VA_LOCAL_DECL   va_list ap
+# define VA_START(f)     va_start(ap, f)
+# define VA_SHIFT(v,t)  ;   /* no-op for ANSI */
+# define VA_END          va_end(ap)
+#else
+# if defined(HAVE_VARARGS_H)
+#  include <varargs.h>
+#  undef HAVE_STDARGS
+#  define VA_LOCAL_DECL   va_list ap
+#  define VA_START(f)     va_start(ap)      /* f is ignored! */
+#  define VA_SHIFT(v,t) v = va_arg(ap,t)
+#  define VA_END        va_end(ap)
+# else
+/*XX ** NO VARARGS ** XX*/
+# endif
+#endif
+
+/*int snprintf (char *str, size_t count, const char *fmt, ...);*/
+/*int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);*/
+
+static void dopr (char *buffer, size_t maxlen, const char *format, 
+                  va_list args);
+static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
+                   char *value, int flags, int min, int max);
+static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
+                   long value, int base, int min, int max, int flags);
+static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
+                  long double fvalue, int min, int max, int flags);
+static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
+
+/*
+ * dopr(): poor man's version of doprintf
+ */
+
+/* format read states */
+#define DP_S_DEFAULT 0
+#define DP_S_FLAGS   1
+#define DP_S_MIN     2
+#define DP_S_DOT     3
+#define DP_S_MAX     4
+#define DP_S_MOD     5
+#define DP_S_CONV    6
+#define DP_S_DONE    7
+
+/* format flags - Bits */
+#define DP_F_MINUS     (1 << 0)
+#define DP_F_PLUS      (1 << 1)
+#define DP_F_SPACE     (1 << 2)
+#define DP_F_NUM       (1 << 3)
+#define DP_F_ZERO      (1 << 4)
+#define DP_F_UP        (1 << 5)
+#define DP_F_UNSIGNED  (1 << 6)
+
+/* Conversion Flags */
+#define DP_C_SHORT   1
+#define DP_C_LONG    2
+#define DP_C_LDOUBLE 3
+
+#define char_to_int(p) (p - '0')
+#define MAX(p,q) ((p >= q) ? p : q)
+
+static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
+{
+  char ch;
+  long value;
+  long double fvalue;
+  char *strvalue;
+  int min;
+  int max;
+  int state;
+  int flags;
+  int cflags;
+  size_t currlen;
+  
+  state = DP_S_DEFAULT;
+  currlen = flags = cflags = min = 0;
+  max = -1;
+  ch = *format++;
+
+  while (state != DP_S_DONE)
+  {
+    if ((ch == '\0') || (currlen >= maxlen)) 
+      state = DP_S_DONE;
+
+    switch(state) 
+    {
+    case DP_S_DEFAULT:
+      if (ch == '%') 
+       state = DP_S_FLAGS;
+      else 
+       dopr_outch (buffer, &currlen, maxlen, ch);
+      ch = *format++;
+      break;
+    case DP_S_FLAGS:
+      switch (ch) 
+      {
+      case '-':
+       flags |= DP_F_MINUS;
+        ch = *format++;
+       break;
+      case '+':
+       flags |= DP_F_PLUS;
+        ch = *format++;
+       break;
+      case ' ':
+       flags |= DP_F_SPACE;
+        ch = *format++;
+       break;
+      case '#':
+       flags |= DP_F_NUM;
+        ch = *format++;
+       break;
+      case '0':
+       flags |= DP_F_ZERO;
+        ch = *format++;
+       break;
+      default:
+       state = DP_S_MIN;
+       break;
+      }
+      break;
+    case DP_S_MIN:
+      if (isdigit((unsigned char)ch)) 
+      {
+       min = 10*min + char_to_int (ch);
+       ch = *format++;
+      } 
+      else if (ch == '*') 
+      {
+       min = va_arg (args, int);
+       ch = *format++;
+       state = DP_S_DOT;
+      } 
+      else 
+       state = DP_S_DOT;
+      break;
+    case DP_S_DOT:
+      if (ch == '.') 
+      {
+       state = DP_S_MAX;
+       ch = *format++;
+      } 
+      else 
+       state = DP_S_MOD;
+      break;
+    case DP_S_MAX:
+      if (isdigit((unsigned char)ch)) 
+      {
+       if (max < 0)
+         max = 0;
+       max = 10*max + char_to_int (ch);
+       ch = *format++;
+      } 
+      else if (ch == '*') 
+      {
+       max = va_arg (args, int);
+       ch = *format++;
+       state = DP_S_MOD;
+      } 
+      else 
+       state = DP_S_MOD;
+      break;
+    case DP_S_MOD:
+      /* Currently, we don't support Long Long, bummer */
+      switch (ch) 
+      {
+      case 'h':
+       cflags = DP_C_SHORT;
+       ch = *format++;
+       break;
+      case 'l':
+       cflags = DP_C_LONG;
+       ch = *format++;
+       break;
+      case 'L':
+       cflags = DP_C_LDOUBLE;
+       ch = *format++;
+       break;
+      default:
+       break;
+      }
+      state = DP_S_CONV;
+      break;
+    case DP_S_CONV:
+      switch (ch) 
+      {
+      case 'd':
+      case 'i':
+       if (cflags == DP_C_SHORT) 
+         value = va_arg (args, short int);
+       else if (cflags == DP_C_LONG)
+         value = va_arg (args, long int);
+       else
+         value = va_arg (args, int);
+       fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
+       break;
+      case 'o':
+       flags |= DP_F_UNSIGNED;
+       if (cflags == DP_C_SHORT)
+         value = va_arg (args, unsigned short int);
+       else if (cflags == DP_C_LONG)
+         value = va_arg (args, unsigned long int);
+       else
+         value = va_arg (args, unsigned int);
+       fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
+       break;
+      case 'u':
+       flags |= DP_F_UNSIGNED;
+       if (cflags == DP_C_SHORT)
+         value = va_arg (args, unsigned short int);
+       else if (cflags == DP_C_LONG)
+         value = va_arg (args, unsigned long int);
+       else
+         value = va_arg (args, unsigned int);
+       fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
+       break;
+      case 'X':
+       flags |= DP_F_UP;
+      case 'x':
+       flags |= DP_F_UNSIGNED;
+       if (cflags == DP_C_SHORT)
+         value = va_arg (args, unsigned short int);
+       else if (cflags == DP_C_LONG)
+         value = va_arg (args, unsigned long int);
+       else
+         value = va_arg (args, unsigned int);
+       fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
+       break;
+      case 'f':
+       if (cflags == DP_C_LDOUBLE)
+         fvalue = va_arg (args, long double);
+       else
+         fvalue = va_arg (args, double);
+       /* um, floating point? */
+       fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
+       break;
+      case 'E':
+       flags |= DP_F_UP;
+      case 'e':
+       if (cflags == DP_C_LDOUBLE)
+         fvalue = va_arg (args, long double);
+       else
+         fvalue = va_arg (args, double);
+       break;
+      case 'G':
+       flags |= DP_F_UP;
+      case 'g':
+       if (cflags == DP_C_LDOUBLE)
+         fvalue = va_arg (args, long double);
+       else
+         fvalue = va_arg (args, double);
+       break;
+      case 'c':
+       dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
+       break;
+      case 's':
+       strvalue = va_arg (args, char *);
+       if (max < 0) 
+         max = maxlen; /* ie, no max */
+       fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
+       break;
+      case 'p':
+       strvalue = va_arg (args, void *);
+       fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
+       break;
+      case 'n':
+       if (cflags == DP_C_SHORT) 
+       {
+         short int *num;
+         num = va_arg (args, short int *);
+         *num = currlen;
+        } 
+       else if (cflags == DP_C_LONG) 
+       {
+         long int *num;
+         num = va_arg (args, long int *);
+         *num = currlen;
+        } 
+       else 
+       {
+         int *num;
+         num = va_arg (args, int *);
+         *num = currlen;
+        }
+       break;
+      case '%':
+       dopr_outch (buffer, &currlen, maxlen, ch);
+       break;
+      case 'w':
+       /* not supported yet, treat as next char */
+       ch = *format++;
+       break;
+      default:
+       /* Unknown, skip */
+       break;
+      }
+      ch = *format++;
+      state = DP_S_DEFAULT;
+      flags = cflags = min = 0;
+      max = -1;
+      break;
+    case DP_S_DONE:
+      break;
+    default:
+      /* hmm? */
+      break; /* some picky compilers need this */
+    }
+  }
+  if (currlen < maxlen - 1) 
+    buffer[currlen] = '\0';
+  else 
+    buffer[maxlen - 1] = '\0';
+}
+
+static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
+                   char *value, int flags, int min, int max)
+{
+  int padlen, strln;     /* amount to pad */
+  int cnt = 0;
+  
+  if (value == 0)
+  {
+    value = "<NULL>";
+  }
+
+  for (strln = 0; value[strln]; ++strln); /* strlen */
+  padlen = min - strln;
+  if (padlen < 0) 
+    padlen = 0;
+  if (flags & DP_F_MINUS) 
+    padlen = -padlen; /* Left Justify */
+
+  while ((padlen > 0) && (cnt < max)) 
+  {
+    dopr_outch (buffer, currlen, maxlen, ' ');
+    --padlen;
+    ++cnt;
+  }
+  while (*value && (cnt < max)) 
+  {
+    dopr_outch (buffer, currlen, maxlen, *value++);
+    ++cnt;
+  }
+  while ((padlen < 0) && (cnt < max)) 
+  {
+    dopr_outch (buffer, currlen, maxlen, ' ');
+    ++padlen;
+    ++cnt;
+  }
+}
+
+/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
+
+static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
+                   long value, int base, int min, int max, int flags)
+{
+  int signvalue = 0;
+  unsigned long uvalue;
+  char convert[20];
+  int place = 0;
+  int spadlen = 0; /* amount to space pad */
+  int zpadlen = 0; /* amount to zero pad */
+  int caps = 0;
+  
+  if (max < 0)
+    max = 0;
+
+  uvalue = value;
+
+  if(!(flags & DP_F_UNSIGNED))
+  {
+    if( value < 0 ) {
+      signvalue = '-';
+      uvalue = -value;
+    }
+    else
+      if (flags & DP_F_PLUS)  /* Do a sign (+/i) */
+       signvalue = '+';
+    else
+      if (flags & DP_F_SPACE)
+       signvalue = ' ';
+  }
+  
+  if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
+
+  do {
+    convert[place++] =
+      (caps? "0123456789ABCDEF":"0123456789abcdef")
+      [uvalue % (unsigned)base  ];
+    uvalue = (uvalue / (unsigned)base );
+  } while(uvalue && (place < 20));
+  if (place == 20) place--;
+  convert[place] = 0;
+
+  zpadlen = max - place;
+  spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
+  if (zpadlen < 0) zpadlen = 0;
+  if (spadlen < 0) spadlen = 0;
+  if (flags & DP_F_ZERO)
+  {
+    zpadlen = MAX(zpadlen, spadlen);
+    spadlen = 0;
+  }
+  if (flags & DP_F_MINUS) 
+    spadlen = -spadlen; /* Left Justifty */
+
+#ifdef DEBUG_SNPRINTF
+  dprint (1, (debugfile, "zpad: %d, spad: %d, min: %d, max: %d, place: %d\n",
+      zpadlen, spadlen, min, max, place));
+#endif
+
+  /* Spaces */
+  while (spadlen > 0) 
+  {
+    dopr_outch (buffer, currlen, maxlen, ' ');
+    --spadlen;
+  }
+
+  /* Sign */
+  if (signvalue) 
+    dopr_outch (buffer, currlen, maxlen, signvalue);
+
+  /* Zeros */
+  if (zpadlen > 0) 
+  {
+    while (zpadlen > 0)
+    {
+      dopr_outch (buffer, currlen, maxlen, '0');
+      --zpadlen;
+    }
+  }
+
+  /* Digits */
+  while (place > 0) 
+    dopr_outch (buffer, currlen, maxlen, convert[--place]);
+  
+  /* Left Justified spaces */
+  while (spadlen < 0) {
+    dopr_outch (buffer, currlen, maxlen, ' ');
+    ++spadlen;
+  }
+}
+
+static long double abs_val (long double value)
+{
+  long double result = value;
+
+  if (value < 0)
+    result = -value;
+
+  return result;
+}
+
+static long double pow10 (int exp)
+{
+  long double result = 1;
+
+  while (exp)
+  {
+    result *= 10;
+    exp--;
+  }
+  
+  return result;
+}
+
+static long round (long double value)
+{
+  long intpart;
+
+  intpart = value;
+  value = value - intpart;
+  if (value >= 0.5)
+    intpart++;
+
+  return intpart;
+}
+
+static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
+                  long double fvalue, int min, int max, int flags)
+{
+  int signvalue = 0;
+  long double ufvalue;
+  char iconvert[20];
+  char fconvert[20];
+  int iplace = 0;
+  int fplace = 0;
+  int padlen = 0; /* amount to pad */
+  int zpadlen = 0; 
+  int caps = 0;
+  long intpart;
+  long fracpart;
+  
+  /* 
+   * AIX manpage says the default is 0, but Solaris says the default
+   * is 6, and sprintf on AIX defaults to 6
+   */
+  if (max < 0)
+    max = 6;
+
+  ufvalue = abs_val (fvalue);
+
+  if (fvalue < 0)
+    signvalue = '-';
+  else
+    if (flags & DP_F_PLUS)  /* Do a sign (+/i) */
+      signvalue = '+';
+    else
+      if (flags & DP_F_SPACE)
+       signvalue = ' ';
+
+#if 0
+  if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
+#endif
+
+  intpart = ufvalue;
+
+  /* 
+   * Sorry, we only support 9 digits past the decimal because of our 
+   * conversion method
+   */
+  if (max > 9)
+    max = 9;
+
+  /* We "cheat" by converting the fractional part to integer by
+   * multiplying by a factor of 10
+   */
+  fracpart = round ((pow10 (max)) * (ufvalue - intpart));
+
+  if (fracpart >= pow10 (max))
+  {
+    intpart++;
+    fracpart -= pow10 (max);
+  }
+
+#ifdef DEBUG_SNPRINTF
+  dprint (1, (debugfile, "fmtfp: %f =? %d.%d\n", fvalue, intpart, fracpart));
+#endif
+
+  /* Convert integer part */
+  do {
+    iconvert[iplace++] =
+      (caps? "0123456789ABCDEF":"0123456789abcdef")[intpart % 10];
+    intpart = (intpart / 10);
+  } while(intpart && (iplace < 20));
+  if (iplace == 20) iplace--;
+  iconvert[iplace] = 0;
+
+  /* Convert fractional part */
+  do {
+    fconvert[fplace++] =
+      (caps? "0123456789ABCDEF":"0123456789abcdef")[fracpart % 10];
+    fracpart = (fracpart / 10);
+  } while(fracpart && (fplace < 20));
+  if (fplace == 20) fplace--;
+  fconvert[fplace] = 0;
+
+  /* -1 for decimal point, another -1 if we are printing a sign */
+  padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); 
+  zpadlen = max - fplace;
+  if (zpadlen < 0)
+    zpadlen = 0;
+  if (padlen < 0) 
+    padlen = 0;
+  if (flags & DP_F_MINUS) 
+    padlen = -padlen; /* Left Justifty */
+
+  if ((flags & DP_F_ZERO) && (padlen > 0)) 
+  {
+    if (signvalue) 
+    {
+      dopr_outch (buffer, currlen, maxlen, signvalue);
+      --padlen;
+      signvalue = 0;
+    }
+    while (padlen > 0)
+    {
+      dopr_outch (buffer, currlen, maxlen, '0');
+      --padlen;
+    }
+  }
+  while (padlen > 0)
+  {
+    dopr_outch (buffer, currlen, maxlen, ' ');
+    --padlen;
+  }
+  if (signvalue) 
+    dopr_outch (buffer, currlen, maxlen, signvalue);
+
+  while (iplace > 0) 
+    dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]);
+
+  /*
+   * Decimal point.  This should probably use locale to find the correct
+   * char to print out.
+   */
+  dopr_outch (buffer, currlen, maxlen, '.');
+
+  while (fplace > 0) 
+    dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]);
+
+  while (zpadlen > 0)
+  {
+    dopr_outch (buffer, currlen, maxlen, '0');
+    --zpadlen;
+  }
+
+  while (padlen < 0) 
+  {
+    dopr_outch (buffer, currlen, maxlen, ' ');
+    ++padlen;
+  }
+}
+
+static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c)
+{
+  if (*currlen < maxlen)
+    buffer[(*currlen)++] = c;
+}
+#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
+
+#ifndef HAVE_VSNPRINTF
+int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
+{
+  str[0] = 0;
+  dopr(str, count, fmt, args);
+  return(strlen(str));
+}
+#endif /* !HAVE_VSNPRINTF */
+
+#ifndef HAVE_SNPRINTF
+/* VARARGS3 */
+#ifdef HAVE_STDARGS
+int snprintf (char *str,size_t count,const char *fmt,...)
+#else
+int snprintf (va_alist) va_dcl
+#endif
+{
+#ifndef HAVE_STDARGS
+  char *str;
+  size_t count;
+  char *fmt;
+#endif
+  VA_LOCAL_DECL;
+    
+  VA_START (fmt);
+  VA_SHIFT (str, char *);
+  VA_SHIFT (count, size_t );
+  VA_SHIFT (fmt, char *);
+  (void) vsnprintf(str, count, fmt, ap);
+  VA_END;
+  return(strlen(str));
+}
+
+#ifdef TEST_SNPRINTF
+#ifndef LONG_STRING
+#define LONG_STRING 1024
+#endif
+int main (void)
+{
+  char buf1[LONG_STRING];
+  char buf2[LONG_STRING];
+  char *fp_fmt[] = {
+    "%-1.5f",
+    "%1.5f",
+    "%123.9f",
+    "%10.5f",
+    "% 10.5f",
+    "%+22.9f",
+    "%+4.9f",
+    "%01.3f",
+    "%4f",
+    "%3.1f",
+    "%3.2f",
+    NULL
+  };
+  double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996, 
+    0.9996, 1.996, 4.136, 0};
+  char *int_fmt[] = {
+    "%-1.5d",
+    "%1.5d",
+    "%123.9d",
+    "%5.5d",
+    "%10.5d",
+    "% 10.5d",
+    "%+22.33d",
+    "%01.3d",
+    "%4d",
+    NULL
+  };
+  long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
+  int x, y;
+  int fail = 0;
+  int num = 0;
+
+  printf ("Testing snprintf format codes against system sprintf...\n");
+
+  for (x = 0; fp_fmt[x] != NULL ; x++)
+    for (y = 0; fp_nums[y] != 0 ; y++)
+    {
+      snprintf (buf1, sizeof (buf1), fp_fmt[x], fp_nums[y]);
+      sprintf (buf2, fp_fmt[x], fp_nums[y]);
+      if (strcmp (buf1, buf2))
+      {
+       printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf  = %s\n", 
+           fp_fmt[x], buf1, buf2);
+       fail++;
+      }
+      num++;
+    }
+
+  for (x = 0; int_fmt[x] != NULL ; x++)
+    for (y = 0; int_nums[y] != 0 ; y++)
+    {
+      snprintf (buf1, sizeof (buf1), int_fmt[x], int_nums[y]);
+      sprintf (buf2, int_fmt[x], int_nums[y]);
+      if (strcmp (buf1, buf2))
+      {
+       printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf  = %s\n", 
+           int_fmt[x], buf1, buf2);
+       fail++;
+      }
+      num++;
+    }
+  printf ("%d tests failed out of %d.\n", fail, num);
+}
+#endif /* SNPRINTF_TEST */
+
+#endif /* !HAVE_SNPRINTF */
diff --git a/misc.h b/misc.h
new file mode 100644 (file)
index 0000000..384b6cc
--- /dev/null
+++ b/misc.h
@@ -0,0 +1,32 @@
+#ifndef _MISC_H
+#define _MISC_H
+
+char           *revstr(char *str);
+char           *strupper(char *str);
+char           *strlower(char *str);
+char           *strtrim(char *);
+
+char           *mkstr (const char *format, ... );
+char           *strconcat (const char *str, ...);
+
+int            safe_strcmp(const char *s1, const char *s2);
+int            safe_strcoll(const char *s1, const char *s2);
+
+char           *my_getcwd();
+
+char           *getaline(FILE *f);
+
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+
+#include <stdarg.h>
+
+#ifndef HAVE_SNPRINTF
+int snprintf (char *str, size_t count, const char *fmt, ...);
+#endif
+#ifndef HAVE_VSNPRINTF
+int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
+#endif
+
+#endif
diff --git a/missing b/missing
new file mode 100755 (executable)
index 0000000..0a7fb5a
--- /dev/null
+++ b/missing
@@ -0,0 +1,283 @@
+#! /bin/sh
+# Common stub for a few missing GNU programs while installing.
+# Copyright 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+if test $# -eq 0; then
+  echo 1>&2 "Try \`$0 --help' for more information"
+  exit 1
+fi
+
+run=:
+
+# In the cases where this matters, `missing' is being run in the
+# srcdir already.
+if test -f configure.ac; then
+  configure_ac=configure.ac
+else
+  configure_ac=configure.in
+fi
+
+case "$1" in
+--run)
+  # Try to run requested program, and just exit if it succeeds.
+  run=
+  shift
+  "$@" && exit 0
+  ;;
+esac
+
+# If it does not exist, or fails to run (possibly an outdated version),
+# try to emulate it.
+case "$1" in
+
+  -h|--h|--he|--hel|--help)
+    echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
+error status if there is no known handling for PROGRAM.
+
+Options:
+  -h, --help      display this help and exit
+  -v, --version   output version information and exit
+  --run           try to run the given command, and emulate it if it fails
+
+Supported PROGRAM values:
+  aclocal      touch file \`aclocal.m4'
+  autoconf     touch file \`configure'
+  autoheader   touch file \`config.h.in'
+  automake     touch all \`Makefile.in' files
+  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
+  flex         create \`lex.yy.c', if possible, from existing .c
+  help2man     touch the output file
+  lex          create \`lex.yy.c', if possible, from existing .c
+  makeinfo     touch the output file
+  tar          try tar, gnutar, gtar, then tar without non-portable flags
+  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]"
+    ;;
+
+  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+    echo "missing 0.3 - GNU automake"
+    ;;
+
+  -*)
+    echo 1>&2 "$0: Unknown \`$1' option"
+    echo 1>&2 "Try \`$0 --help' for more information"
+    exit 1
+    ;;
+
+  aclocal)
+    echo 1>&2 "\
+WARNING: \`$1' is missing on your system.  You should only need it if
+         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
+         to install the \`Automake' and \`Perl' packages.  Grab them from
+         any GNU archive site."
+    touch aclocal.m4
+    ;;
+
+  autoconf)
+    echo 1>&2 "\
+WARNING: \`$1' is missing on your system.  You should only need it if
+         you modified \`${configure_ac}'.  You might want to install the
+         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
+         archive site."
+    touch configure
+    ;;
+
+  autoheader)
+    echo 1>&2 "\
+WARNING: \`$1' is missing on your system.  You should only need it if
+         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
+         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
+         from any GNU archive site."
+    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
+    test -z "$files" && files="config.h"
+    touch_files=
+    for f in $files; do
+      case "$f" in
+      *:*) touch_files="$touch_files "`echo "$f" |
+                                      sed -e 's/^[^:]*://' -e 's/:.*//'`;;
+      *) touch_files="$touch_files $f.in";;
+      esac
+    done
+    touch $touch_files
+    ;;
+
+  automake)
+    echo 1>&2 "\
+WARNING: \`$1' is missing on your system.  You should only need it if
+         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
+         You might want to install the \`Automake' and \`Perl' packages.
+         Grab them from any GNU archive site."
+    find . -type f -name Makefile.am -print |
+          sed 's/\.am$/.in/' |
+          while read f; do touch "$f"; done
+    ;;
+
+  bison|yacc)
+    echo 1>&2 "\
+WARNING: \`$1' is missing on your system.  You should only need it if
+         you modified a \`.y' file.  You may need the \`Bison' package
+         in order for those modifications to take effect.  You can get
+         \`Bison' from any GNU archive site."
+    rm -f y.tab.c y.tab.h
+    if [ $# -ne 1 ]; then
+        eval LASTARG="\${$#}"
+       case "$LASTARG" in
+       *.y)
+           SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
+           if [ -f "$SRCFILE" ]; then
+                cp "$SRCFILE" y.tab.c
+           fi
+           SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
+           if [ -f "$SRCFILE" ]; then
+                cp "$SRCFILE" y.tab.h
+           fi
+         ;;
+       esac
+    fi
+    if [ ! -f y.tab.h ]; then
+       echo >y.tab.h
+    fi
+    if [ ! -f y.tab.c ]; then
+       echo 'main() { return 0; }' >y.tab.c
+    fi
+    ;;
+
+  lex|flex)
+    echo 1>&2 "\
+WARNING: \`$1' is missing on your system.  You should only need it if
+         you modified a \`.l' file.  You may need the \`Flex' package
+         in order for those modifications to take effect.  You can get
+         \`Flex' from any GNU archive site."
+    rm -f lex.yy.c
+    if [ $# -ne 1 ]; then
+        eval LASTARG="\${$#}"
+       case "$LASTARG" in
+       *.l)
+           SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
+           if [ -f "$SRCFILE" ]; then
+                cp "$SRCFILE" lex.yy.c
+           fi
+         ;;
+       esac
+    fi
+    if [ ! -f lex.yy.c ]; then
+       echo 'main() { return 0; }' >lex.yy.c
+    fi
+    ;;
+
+  help2man)
+    echo 1>&2 "\
+WARNING: \`$1' is missing on your system.  You should only need it if
+        you modified a dependency of a manual page.  You may need the
+        \`Help2man' package in order for those modifications to take
+        effect.  You can get \`Help2man' from any GNU archive site."
+
+    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
+    if test -z "$file"; then
+       file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
+    fi
+    if [ -f "$file" ]; then
+       touch $file
+    else
+       test -z "$file" || exec >$file
+       echo ".ab help2man is required to generate this page"
+       exit 1
+    fi
+    ;;
+
+  makeinfo)
+    if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then
+       # We have makeinfo, but it failed.
+       exit 1
+    fi
+
+    echo 1>&2 "\
+WARNING: \`$1' is missing on your system.  You should only need it if
+         you modified a \`.texi' or \`.texinfo' file, or any other file
+         indirectly affecting the aspect of the manual.  The spurious
+         call might also be the consequence of using a buggy \`make' (AIX,
+         DU, IRIX).  You might want to install the \`Texinfo' package or
+         the \`GNU make' package.  Grab either from any GNU archive site."
+    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
+    if test -z "$file"; then
+      file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+      file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
+    fi
+    touch $file
+    ;;
+
+  tar)
+    shift
+    if test -n "$run"; then
+      echo 1>&2 "ERROR: \`tar' requires --run"
+      exit 1
+    fi
+
+    # We have already tried tar in the generic part.
+    # Look for gnutar/gtar before invocation to avoid ugly error
+    # messages.
+    if (gnutar --version > /dev/null 2>&1); then
+       gnutar ${1+"$@"} && exit 0
+    fi
+    if (gtar --version > /dev/null 2>&1); then
+       gtar ${1+"$@"} && exit 0
+    fi
+    firstarg="$1"
+    if shift; then
+       case "$firstarg" in
+       *o*)
+           firstarg=`echo "$firstarg" | sed s/o//`
+           tar "$firstarg" ${1+"$@"} && exit 0
+           ;;
+       esac
+       case "$firstarg" in
+       *h*)
+           firstarg=`echo "$firstarg" | sed s/h//`
+           tar "$firstarg" ${1+"$@"} && exit 0
+           ;;
+       esac
+    fi
+
+    echo 1>&2 "\
+WARNING: I can't seem to be able to run \`tar' with the given arguments.
+         You may want to install GNU tar or Free paxutils, or check the
+         command line arguments."
+    exit 1
+    ;;
+
+  *)
+    echo 1>&2 "\
+WARNING: \`$1' is needed, and you do not seem to have it handy on your
+         system.  You might have modified some files without having the
+         proper tools for further handling them.  Check the \`README' file,
+         it often tells you about the needed prerequirements for installing
+         this package.  You may also peek at any GNU archive site, in case
+         some other package would contain this missing \`$1' program."
+    exit 1
+    ;;
+esac
+
+exit 0
diff --git a/mkinstalldirs b/mkinstalldirs
new file mode 100755 (executable)
index 0000000..0609792
--- /dev/null
@@ -0,0 +1,40 @@
+#! /bin/sh
+# mkinstalldirs --- make directory hierarchy
+# Author: Noah Friedman <friedman@prep.ai.mit.edu>
+# Created: 1993-05-16
+# Public domain
+
+# $Id: mkinstalldirs,v 1.1.1.1 2001/03/12 10:13:19 jheinonen Exp $
+
+errstatus=0
+
+for file
+do
+   set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
+   shift
+
+   pathcomp=
+   for d
+   do
+     pathcomp="$pathcomp$d"
+     case "$pathcomp" in
+       -* ) pathcomp=./$pathcomp ;;
+     esac
+
+     if test ! -d "$pathcomp"; then
+        echo "mkdir $pathcomp" 1>&2
+
+        mkdir "$pathcomp" || lasterr=$?
+
+        if test ! -d "$pathcomp"; then
+         errstatus=$lasterr
+        fi
+     fi
+
+     pathcomp="$pathcomp/"
+   done
+done
+
+exit $errstatus
+
+# mkinstalldirs ends here
diff --git a/options.c b/options.c
new file mode 100644 (file)
index 0000000..c1c1677
--- /dev/null
+++ b/options.c
@@ -0,0 +1,157 @@
+
+/*
+ * $Id: options.c,v 1.7 2001/08/23 09:39:56 jheinonen Exp $
+ *
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "abook_curses.h"
+#include "abook.h"
+#include "options.h"
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+
+struct conff_node *abook_config;
+
+static int     rcfile_exist();
+static void    default_options();
+
+extern char *rcfile;
+
+static char *
+abook_opt_conff_get_val(char *key)
+{
+       int tried;
+       char *value = NULL;
+
+
+       for(tried = 0; tried < 2; ) {
+               if( ( value = conff_get_value(abook_config, key) )
+                               == 0 ) {
+                       tried ++;
+                       default_options(); /* try with defaults */
+               } else
+                       return value;
+       }
+       return NULL;
+}
+
+int
+options_get_int(char *key)
+{
+       char *value;
+       int ret;
+       
+       if( ( value = abook_opt_conff_get_val(key) )
+                       == NULL)
+               return 1;
+
+       if( !strcasecmp(value, "true") )
+               ret = 1;
+       else
+       if( !strcasecmp(value, "false") )
+               ret = 0;
+       else
+               ret = safe_atoi(value);
+       
+       return ret;
+}
+       
+char *
+options_get_str(char *key)
+{
+       return abook_opt_conff_get_val(key); 
+}
+               
+void
+init_options()
+{
+       abook_config = NULL;
+
+       if( rcfile_exist() )
+               load_options();
+       else
+               default_options();
+}
+
+void
+close_config()
+{
+       save_options();
+
+       conff_free_nodes(abook_config);
+}
+
+static int
+rcfile_exist()
+{
+       return ( (0 == access(SYSWIDE_RCFILE, F_OK)) ||
+                       (0 == access(rcfile, F_OK)) );
+}
+
+void
+load_options()
+{
+       int ret;
+       
+        if( (ret = conff_load_file(&abook_config, rcfile,
+                               REPLACE_KEY)) > 0) {
+               fprintf(stderr, "%s: parse error at line %d\n", rcfile, ret);
+               exit(1);
+       }
+
+       if( (ret = conff_load_file(&abook_config, SYSWIDE_RCFILE,
+                                       DONT_REPLACE_KEY )) > 0) {
+               fprintf(stderr, "%s: parse error at line %d\n",
+                               SYSWIDE_RCFILE, ret);
+               exit(1);
+       }
+}
+
+void
+save_options()
+{
+       if( rcfile_exist() ) /* don't overwrite existing config */
+               return;
+
+       conff_save_file(abook_config, rcfile);
+}
+
+static void
+options_add_key(char *key, char *value)
+{
+       const int flags = DONT_REPLACE_KEY;
+
+       conff_add_key(&abook_config, key, value, flags);
+}
+
+static void
+default_options()
+{
+       options_add_key("autosave", "true");
+
+       options_add_key("show_all_emails", "true");
+       options_add_key("emailpos", "25");
+       options_add_key("extra_column", "7");
+       options_add_key("extra_alternative", "-1");
+       options_add_key("extrapos", "65");
+
+       options_add_key("mutt_command", "mutt");
+       options_add_key("mutt_return_all_emails", "true");
+
+       options_add_key("print_command", "lpr");
+
+       options_add_key("filesel_sort", "false");
+
+       options_add_key("www_command", "lynx");
+
+       options_add_key("address_style", "eu");
+
+       options_add_key("use_ascii_only", "false");
+}
diff --git a/options.h b/options.h
new file mode 100644 (file)
index 0000000..7e3ee27
--- /dev/null
+++ b/options.h
@@ -0,0 +1,16 @@
+#ifndef _OPTIONS_H
+#define _OPTIONS_H
+
+#define RCFILE         ".abookrc"
+#define SYSWIDE_RCFILE "/etc/abookrc"
+
+#include "conff.h"
+
+int    options_get_int(char *key);
+char   *options_get_str(char *key);
+void   init_options();
+void   close_config();
+void   load_options();
+void   save_options();
+
+#endif
diff --git a/sample.abookrc b/sample.abookrc
new file mode 100644 (file)
index 0000000..847e4ff
--- /dev/null
@@ -0,0 +1,52 @@
+# sample abook configuration file
+# see abookrc(5) for detailed explanation
+
+# Automatically save database on exit
+autosave=true
+
+# Show all email addresses in list
+show_all_emails=true
+
+# Screen column for email field to start
+emailpos=25
+
+# Field to be used in the extra column
+extra_column=phone
+# frequently used values:
+#      -1              disabled
+#      phone           Home Phone
+#      workphone       Work Phone
+#      fax             Fax
+#      mobile          Mobile Phone
+#      nick            Nick / Alias
+#      url             URL
+
+# Specify an alternative field to be displayed in the extra
+# column if there is no data for the field specified in
+# extra_column for a particular item.  
+extra_alternative=-1
+
+# Screen column for the extra field to start
+extrapos=65
+
+# Command used to start mutt
+mutt_command=mutt
+
+# Return all email addresses to a mutt query
+mutt_return_all_emails=true
+
+# Command used to print
+print_command=lpr
+
+# Sort files in fileselector (alphabetic order)
+filesel_sort=false
+
+# Command used to start the web browser
+www_command=lynx
+
+# address style [eu|us|uk]
+address_style=eu
+
+# use ASCII characters only
+use_ascii_only=false
+
diff --git a/stamp-h.in b/stamp-h.in
new file mode 100644 (file)
index 0000000..9788f70
--- /dev/null
@@ -0,0 +1 @@
+timestamp
diff --git a/ui.c b/ui.c
new file mode 100644 (file)
index 0000000..66049db
--- /dev/null
+++ b/ui.c
@@ -0,0 +1,632 @@
+
+/*
+ * $Id: ui.c,v 1.15 2001/12/19 20:20:55 jheinonen Exp $
+ *
+ * by JH <jheinonen@users.sourceforge.net>
+ *
+ * Copyright (C) Jaakko Heinonen
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <ctype.h>
+#include "abook.h"
+#include "ui.h"
+#include "edit.h"
+#include "database.h"
+#include "list.h"
+#include "misc.h"
+#include "options.h"
+#include "filter.h"
+#include "estr.h"
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
+#ifdef HAVE_TERMIOS_H
+#      include <termios.h>
+#else
+#      ifdef HAVE_LINUX_TERMIOS_H
+#              include <linux/termios.h>
+#      endif
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#      include <sys/ioctl.h>
+#endif
+
+/*
+ * external variables
+ */
+
+extern int items, curitem;
+extern char *datafile;
+
+/*
+ * internal variables
+ */
+
+int ui_initialized = FALSE;
+
+int should_resize = FALSE;
+int can_resize = FALSE;
+
+WINDOW *top = NULL, *bottom = NULL;
+
+
+
+static void
+init_windows()
+{
+       top = newwin(LIST_TOP - 1, COLS, 0, 0);
+       
+       bottom = newwin(LINES - LIST_BOTTOM, COLS, LIST_BOTTOM, 0);
+}
+
+static void
+free_windows()
+{
+       delwin(top);
+       delwin(bottom);
+}
+
+
+#ifdef SIGWINCH
+static void
+resize_abook()
+{
+#ifdef TIOCGWINSZ
+       struct winsize winsz;
+
+       ioctl (0, TIOCGWINSZ, &winsz);
+#ifdef DEBUG
+       if(winsz.ws_col >= MIN_COLS && winsz.ws_row >= MIN_LINES) {
+               fprintf(stderr, "Warning: COLS=%d, LINES=%d\n", winsz.ws_col, winsz.ws_row);
+       }
+#endif
+               
+       if(winsz.ws_col >= MIN_COLS && winsz.ws_row >= MIN_LINES) {
+#ifdef HAVE_RESIZETERM
+               resizeterm(winsz.ws_row, winsz.ws_col);
+#else
+               COLS = winsz.ws_col;
+               LINES = winsz.ws_row;
+#endif
+       }
+
+       should_resize = FALSE;
+       close_list(); /* we need to recreate windows */
+       init_list();
+       free_windows();
+       init_windows();
+       refresh_screen();
+       refresh();
+#endif /* TIOCGWINSZ */
+}
+
+
+static void
+win_changed(int i)
+{
+       if( can_resize )
+               resize_abook();
+       else
+               should_resize = TRUE;   
+}
+#endif /* SIGWINCH */
+
+
+int
+is_ui_initialized()
+{
+       return ui_initialized;
+}
+
+void
+ui_init_curses()
+{
+       if(!is_ui_initialized())
+               initscr();
+       cbreak();
+       noecho();
+       nonl();
+       intrflush(stdscr, FALSE);
+       keypad(stdscr, TRUE);
+}
+
+int
+init_ui()
+{
+       ui_init_curses();
+#ifdef DEBUG
+        fprintf(stderr, "init_abook():\n");
+        fprintf(stderr, "  COLS = %d, LINES = %d\n", COLS, LINES);
+#endif
+       if( LINES < MIN_LINES || COLS < MIN_COLS ) {
+               clear(); refresh(); endwin();
+               fprintf(stderr, "Your terminal size is %dx%d\n", COLS, LINES);
+               fprintf(stderr, "Terminal is too small. Minium terminal size "
+                               "for abook is "
+                               "%dx%d\n", MIN_COLS, MIN_LINES);
+               return 1;
+       }
+
+#ifdef SIGWINCH
+       signal(SIGWINCH, win_changed);
+#endif
+
+       init_list();
+       init_windows();
+
+       ui_initialized = TRUE;
+
+       return 0;
+}
+
+void
+close_ui()
+{
+       close_list();
+       free_windows();
+       clear();
+       refresh();
+       endwin();
+
+       ui_initialized = FALSE;
+}
+
+
+void
+headerline(char *str)
+{
+       werase(top);
+       
+       mvwhline(top, 1, 0, UI_HLINE_CHAR, COLS);
+       
+       mvwprintw(top, 0, 0, "%s | %s", PACKAGE " " VERSION, str);
+
+       refresh();
+       wrefresh(top);
+}
+               
+
+void
+refresh_screen()
+{
+#ifdef SIGWINCH
+       if( should_resize ) {
+               resize_abook();
+               return;
+       }
+#endif
+       clear();
+       
+       refresh_statusline();
+       headerline(MAIN_HELPLINE);
+       list_headerline();
+
+       refresh_list();
+}
+
+
+void
+statusline_msg(char *msg)
+{
+       clear_statusline();
+       statusline_addstr(msg);
+       getch();
+#ifdef DEBUG
+       fprintf(stderr, "statusline_msg(\"%s\")\n", msg);
+#endif
+       clear_statusline();
+}
+
+void
+statusline_addstr(char *str)
+{
+       mvwaddstr(bottom, 1, 0, str);
+       refresh();
+       wrefresh(bottom);
+}
+
+/*
+ * function statusline_getnstr
+ *
+ * parameters:
+ *  (char *str)
+ *   if n >= 0 str is a pointer which points a place where to store
+ *   the string, else str is ignored
+ *  (int n)
+ *   the maximum length of the string
+ *   If n < 0 function will allocate needed space for the string.
+ *   Value 0 is not allowed for n.
+ *  (int use_filesel)
+ *   if this value is nonzero the fileselector is enabled
+ *
+ *  returns (char *)
+ *   If n < 0 a pointer to a newly allocated string is returned.
+ *   If n > 0 a nonzero value is returned if user has typed a valid
+ *   string. If not NULL value is returned. Never really use the
+ *   _pointer_ if n > 0.
+ *
+ */
+
+char *
+statusline_getnstr(char *str, int n, int use_filesel)
+{
+       char *buf;
+       int y, x;
+
+       getyx(bottom, y, x);
+       wmove(bottom, 1, x);
+       
+       buf = wenter_string(bottom, n,
+                       (use_filesel ? ESTR_USE_FILESEL:0) | ESTR_DONT_WRAP);
+
+       if(n < 0)
+               return buf;
+       
+       if(buf == NULL)
+               str[0] = 0;
+       else
+               strncpy(str, buf, n);
+
+       str[n-1] = 0;
+
+       free(buf);
+
+       return buf;
+}
+
+int
+statusline_ask_boolean(char *msg, int def)
+{
+       int ret;
+       char *msg2 = strconcat(msg,  def ? " (Y/n)?" : " (y/N)?", NULL);
+                       
+       statusline_addstr(msg2);
+
+       free(msg2);
+
+       switch( tolower(getch()) ) {
+               case 'n':
+                       ret = FALSE;
+                       break;
+               case 'y':
+                       ret = TRUE;
+                       break;
+               default:
+                       ret = def;
+                       break;
+       }
+
+       clear_statusline();
+
+       return ret;
+}
+
+
+void
+refresh_statusline()
+{
+       werase(bottom);
+
+       mvwhline(bottom, 0, 0, UI_HLINE_CHAR, COLS);
+       mvwhline(bottom, 2, 0, UI_HLINE_CHAR, COLS);
+
+       refresh();
+       wrefresh(bottom);
+}
+       
+
+char *
+ask_filename(char *prompt, int flags)
+{
+       char *buf = NULL;
+
+       clear_statusline();
+       
+       statusline_addstr(prompt);
+       buf = statusline_getnstr(NULL, -1, flags);
+
+       clear_statusline();
+
+       return buf;
+}
+
+void
+clear_statusline()
+{
+       wmove(bottom, 1, 0);
+       wclrtoeol(bottom);
+       wrefresh(bottom);
+       refresh();
+}
+
+/*
+ * help
+ */
+
+#include "help.h"
+
+void
+display_help(int help)
+{
+       int i;
+       char **tbl;
+       WINDOW *helpw;
+
+       switch(help) {
+               case HELP_MAIN:
+                       tbl = mainhelp;
+                       break;
+               case HELP_EDITOR:
+                       tbl = editorhelp;
+                       break;
+               default:return;
+       }
+
+       helpw = newwin(LINES - 5, COLS - 6, 2, 3);
+       erase();
+       headerline("help");
+       
+       for( i = 0; tbl[i] != NULL; i++) {
+               waddstr(helpw, tbl[i]);
+               if( ( !( (i+1) % (LINES-8) ) ) ||
+                       (tbl[i+1] == NULL) ) {
+                       refresh();
+                       wrefresh(helpw);
+                       refresh_statusline();
+                       statusline_msg("Press any key to continue...");
+                       wclear(helpw);
+               }
+       }
+
+       clear_statusline();
+       delwin(helpw);
+}
+
+/*
+ * end of help
+ */
+
+char *selected;
+extern int curitem;
+
+void
+get_commands()
+{
+       int ch;
+
+       for(;;) {
+               can_resize = TRUE; /* it's safe to resize now */
+               hide_cursor();
+               if( should_resize )
+                       refresh_screen();
+               ch = getch();
+               show_cursor();
+               can_resize = FALSE; /* it's not safe to resize anymore */
+               switch( ch ) {
+                       case 'q': return;
+                       case 'Q': print_stderr(selected_items() ?
+                                                 -1 : list_current_item());
+                                 return;
+                       case '?':
+                                 display_help(HELP_MAIN);
+                                 refresh_screen();
+                                 break;
+                       case 'a': add_item();           break;
+                       case '\r': edit_item(-1);       break;
+                       case KEY_DC:
+                       case 'd':
+                       case 'r': ui_remove_items();    break;
+                       case 12: refresh_screen();      break;
+
+                       case 'k':
+                       case KEY_UP: scroll_up();       break;
+                       case 'j':
+                       case KEY_DOWN: scroll_down();   break;
+                       case 'K':
+                       case KEY_PPAGE: page_up();      break;
+                       case 'J':
+                       case KEY_NPAGE: page_down();    break;
+
+                       case 'g':
+                       case KEY_HOME: goto_home();     break;
+                       case 'G':
+                       case KEY_END: goto_end();       break;
+
+                       case 'w': save_database();
+                                 break;
+                       case 'l': ui_read_database();   break;
+                       case 'i': import_database();    break;
+                       case 'e': export_database();    break;
+                       case 'C': ui_clear_database();  break;
+
+                       case 'o': ui_open_datafile();   break;
+
+                       case 's': sort_database();      break;
+                       case 'S': sort_surname();       break;
+
+                       case '/': ui_find(0);           break;
+                       case '\\': ui_find(1);          break;
+
+                       case ' ': if(curitem >= 0) {
+                                  selected[curitem] = !selected[curitem];
+                                  ui_print_number_of_items();
+                                  refresh_list();
+                                 }
+                               break;
+                       case '+': select_all();
+                                 refresh_list();
+                               break;
+                       case '-': select_none();
+                                 refresh_list();
+                               break;
+                       case '*': invert_selection();
+                                 refresh_list();
+                                break;
+                       case 'A': move_curitem(MOVE_ITEM_UP);
+                               break;
+                       case 'Z': move_curitem(MOVE_ITEM_DOWN);
+                               break;
+
+                       case 'm': launch_mutt(selected_items() ?
+                                                 -1 : list_current_item());
+                                 refresh_screen();
+                                 break;
+
+                       case 'p': ui_print_database(); break;
+
+                       case 'u': launch_wwwbrowser(list_current_item());
+                                 refresh_screen();
+                                 break;
+               }
+       }
+}
+
+
+void
+ui_remove_items()
+{
+       if(list_is_empty())
+               return;
+
+       if(statusline_ask_boolean("Remove selected item(s)", TRUE))
+               remove_selected_items();
+
+       clear_statusline();     
+       refresh_list();
+}
+
+void
+ui_clear_database()
+{
+       if(statusline_ask_boolean("Clear WHOLE database", FALSE)) {
+               close_database();
+               refresh_list();
+       }
+}
+
+void
+ui_find(int next)
+{
+       int item;
+       static char findstr[MAX_FIELD_LEN];
+       int search_fields[] = {NAME, EMAIL, NICK, -1};
+
+       if(next) {
+               if( !*findstr )
+                       return;
+       } else {
+               clear_statusline();
+               statusline_addstr("/");
+               statusline_getnstr(findstr, MAX_FIELD_LEN - 1, 0);
+               clear_statusline();
+       }
+
+       if( (item = find_item(findstr, curitem + !!next,
+                                       search_fields )) >= 0 ) {
+               curitem = item;
+               refresh_list();
+       }
+
+}
+
+
+void
+ui_print_number_of_items()
+{
+       char *str = mkstr("     " "|%3d/%3d", selected_items(), items);
+
+       mvaddstr(0, COLS-strlen(str), str);
+
+       free(str);
+}
+
+void
+ui_read_database()
+{
+       if(items > 0)
+               if(!statusline_ask_boolean("Your current data will be lost - "
+                               "Press 'y' to continue", FALSE))
+                       return;
+
+       load_database(datafile);
+       refresh_list();
+}
+
+
+void
+ui_print_database()
+{
+       FILE *handle;
+       char *command = options_get_str("print_command");
+       int mode;
+
+       if( list_is_empty() )
+               return;
+
+       statusline_addstr("Print All/Selected/Cancel (a/s/C)?");
+
+       switch( tolower(getch()) ) {
+               case 'a':
+                       mode = ENUM_ALL;
+                       break;
+               case 's':
+                       if( !selected_items() ) {
+                               statusline_msg("No selected items");
+                               return;
+                       }
+                       mode = ENUM_SELECTED;
+                       break;
+               default:
+                       clear_statusline();
+                       return;
+       }
+
+       clear_statusline();
+
+       if( ! *command || (handle = popen(command, "w")) == NULL)
+               return;
+
+       fexport("text", handle, mode);
+       
+       pclose(handle);
+}
+
+
+void
+ui_open_datafile()
+{
+       char *filename;
+
+       filename = ask_filename("File to open: ", 1);
+
+       if( !filename ) {
+               refresh_screen();
+               return;
+       }
+
+       if( options_get_int("autosave") )
+               save_database();
+       else if(statusline_ask_boolean("Save current database", FALSE))
+               save_database();
+
+       close_database();
+
+       load_database(filename);
+
+       if( items == 0 ) {
+               statusline_msg("Sorry, that specified file appears not to be a valid abook addressbook");
+               load_database(datafile);
+       } else {
+               free(datafile);
+               datafile = strdup(filename);
+       }
+
+       refresh_screen();
+       free(filename);
+}
diff --git a/ui.h b/ui.h
new file mode 100644 (file)
index 0000000..5c3cac1
--- /dev/null
+++ b/ui.h
@@ -0,0 +1,41 @@
+#ifndef _UI_H
+#define _UI_H
+
+#include "abook_curses.h"
+
+enum {
+       HELP_MAIN,
+       HELP_EDITOR
+};
+
+int            is_ui_initialized();
+void           ui_init_curses();
+int            init_ui();
+void           close_ui();
+void           headerline(char *str);
+void            refresh_screen();
+void            statusline_msg(char *msg);
+char           *ask_filename(char *prompt, int flags);
+int            statusline_ask_boolean(char *msg, int def);
+void            clear_statusline();
+void           display_help(int help);
+void           statusline_addstr(char *str);
+char           *statusline_getnstr(char *str, int n, int use_filesel);
+void           refresh_statusline();
+void           get_commands();
+void           ui_remove_items();
+void           ui_clear_database();
+void           ui_find(int next);
+void           ui_print_number_of_items();
+void           ui_read_database();
+char           *get_surname(char *s);
+void           ui_print_database();
+void           ui_open_datafile();
+
+
+#include "options.h" /* needed for options_get_int */
+
+#define UI_HLINE_CHAR          options_get_int("use_ascii_only") ? \
+                                       '-' : ACS_HLINE
+
+#endif