home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-09-22 | 59.4 KB | 1,853 lines |
- Newsgroups: comp.sources.misc
- From: hm@hcshh.hcs.de (Hellmuth Michaelis)
- Subject: v39i098: cwish - Window Shell / Filemanager v1.00, Part02/04
- Message-ID: <1993Sep22.161434.25876@sparky.sterling.com>
- X-Md4-Signature: 225384db6f2c7c0d521458fe5ee974a8
- Sender: kent@sparky.sterling.com (Kent Landfield)
- Reply-To: hm@hcshh.hcs.de
- Organization: HCS Hanseatischer Computerservice GmbH
- Date: Wed, 22 Sep 1993 16:14:34 GMT
- Approved: kent@sparky.sterling.com
-
- Submitted-by: hm@hcshh.hcs.de (Hellmuth Michaelis)
- Posting-number: Volume 39, Issue 98
- Archive-name: cwish/part02
- Environment: HP-UX, 386BSD, NETBSD, ANSI-C, SYSV-CURSES
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: COPYING chdir.c history.c wish.c
- # Wrapped by kent@sparky on Wed Sep 22 10:49:57 1993
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 2 (of 4)."'
- if test -f 'COPYING' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'COPYING'\"
- else
- echo shar: Extracting \"'COPYING'\" \(17982 characters\)
- sed "s/^X//" >'COPYING' <<'END_OF_FILE'
- X GNU GENERAL PUBLIC LICENSE
- X Version 2, June 1991
- X
- X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- X 675 Mass Ave, Cambridge, MA 02139, USA
- X Everyone is permitted to copy and distribute verbatim copies
- X of this license document, but changing it is not allowed.
- X
- X Preamble
- X
- X The licenses for most software are designed to take away your
- Xfreedom to share and change it. By contrast, the GNU General Public
- XLicense is intended to guarantee your freedom to share and change free
- Xsoftware--to make sure the software is free for all its users. This
- XGeneral Public License applies to most of the Free Software
- XFoundation's software and to any other program whose authors commit to
- Xusing it. (Some other Free Software Foundation software is covered by
- Xthe GNU Library General Public License instead.) You can apply it to
- Xyour programs, too.
- X
- X When we speak of free software, we are referring to freedom, not
- Xprice. Our General Public Licenses are designed to make sure that you
- Xhave the freedom to distribute copies of free software (and charge for
- Xthis service if you wish), that you receive source code or can get it
- Xif you want it, that you can change the software or use pieces of it
- Xin new free programs; and that you know you can do these things.
- X
- X To protect your rights, we need to make restrictions that forbid
- Xanyone to deny you these rights or to ask you to surrender the rights.
- XThese restrictions translate to certain responsibilities for you if you
- Xdistribute copies of the software, or if you modify it.
- X
- X For example, if you distribute copies of such a program, whether
- Xgratis or for a fee, you must give the recipients all the rights that
- Xyou have. You must make sure that they, too, receive or can get the
- Xsource code. And you must show them these terms so they know their
- Xrights.
- X
- X We protect your rights with two steps: (1) copyright the software, and
- X(2) offer you this license which gives you legal permission to copy,
- Xdistribute and/or modify the software.
- X
- X Also, for each author's protection and ours, we want to make certain
- Xthat everyone understands that there is no warranty for this free
- Xsoftware. If the software is modified by someone else and passed on, we
- Xwant its recipients to know that what they have is not the original, so
- Xthat any problems introduced by others will not reflect on the original
- Xauthors' reputations.
- X
- X Finally, any free program is threatened constantly by software
- Xpatents. We wish to avoid the danger that redistributors of a free
- Xprogram will individually obtain patent licenses, in effect making the
- Xprogram proprietary. To prevent this, we have made it clear that any
- Xpatent must be licensed for everyone's free use or not licensed at all.
- X
- X The precise terms and conditions for copying, distribution and
- Xmodification follow.
- X
- X GNU GENERAL PUBLIC LICENSE
- X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- X
- X 0. This License applies to any program or other work which contains
- Xa notice placed by the copyright holder saying it may be distributed
- Xunder the terms of this General Public License. The "Program", below,
- Xrefers to any such program or work, and a "work based on the Program"
- Xmeans either the Program or any derivative work under copyright law:
- Xthat is to say, a work containing the Program or a portion of it,
- Xeither verbatim or with modifications and/or translated into another
- Xlanguage. (Hereinafter, translation is included without limitation in
- Xthe term "modification".) Each licensee is addressed as "you".
- X
- XActivities other than copying, distribution and modification are not
- Xcovered by this License; they are outside its scope. The act of
- Xrunning the Program is not restricted, and the output from the Program
- Xis covered only if its contents constitute a work based on the
- XProgram (independent of having been made by running the Program).
- XWhether that is true depends on what the Program does.
- X
- X 1. You may copy and distribute verbatim copies of the Program's
- Xsource code as you receive it, in any medium, provided that you
- Xconspicuously and appropriately publish on each copy an appropriate
- Xcopyright notice and disclaimer of warranty; keep intact all the
- Xnotices that refer to this License and to the absence of any warranty;
- Xand give any other recipients of the Program a copy of this License
- Xalong with the Program.
- X
- XYou may charge a fee for the physical act of transferring a copy, and
- Xyou may at your option offer warranty protection in exchange for a fee.
- X
- X 2. You may modify your copy or copies of the Program or any portion
- Xof it, thus forming a work based on the Program, and copy and
- Xdistribute such modifications or work under the terms of Section 1
- Xabove, provided that you also meet all of these conditions:
- X
- X a) You must cause the modified files to carry prominent notices
- X stating that you changed the files and the date of any change.
- X
- X b) You must cause any work that you distribute or publish, that in
- X whole or in part contains or is derived from the Program or any
- X part thereof, to be licensed as a whole at no charge to all third
- X parties under the terms of this License.
- X
- X c) If the modified program normally reads commands interactively
- X when run, you must cause it, when started running for such
- X interactive use in the most ordinary way, to print or display an
- X announcement including an appropriate copyright notice and a
- X notice that there is no warranty (or else, saying that you provide
- X a warranty) and that users may redistribute the program under
- X these conditions, and telling the user how to view a copy of this
- X License. (Exception: if the Program itself is interactive but
- X does not normally print such an announcement, your work based on
- X the Program is not required to print an announcement.)
- X
- XThese requirements apply to the modified work as a whole. If
- Xidentifiable sections of that work are not derived from the Program,
- Xand can be reasonably considered independent and separate works in
- Xthemselves, then this License, and its terms, do not apply to those
- Xsections when you distribute them as separate works. But when you
- Xdistribute the same sections as part of a whole which is a work based
- Xon the Program, the distribution of the whole must be on the terms of
- Xthis License, whose permissions for other licensees extend to the
- Xentire whole, and thus to each and every part regardless of who wrote it.
- X
- XThus, it is not the intent of this section to claim rights or contest
- Xyour rights to work written entirely by you; rather, the intent is to
- Xexercise the right to control the distribution of derivative or
- Xcollective works based on the Program.
- X
- XIn addition, mere aggregation of another work not based on the Program
- Xwith the Program (or with a work based on the Program) on a volume of
- Xa storage or distribution medium does not bring the other work under
- Xthe scope of this License.
- X
- X 3. You may copy and distribute the Program (or a work based on it,
- Xunder Section 2) in object code or executable form under the terms of
- XSections 1 and 2 above provided that you also do one of the following:
- X
- X a) Accompany it with the complete corresponding machine-readable
- X source code, which must be distributed under the terms of Sections
- X 1 and 2 above on a medium customarily used for software interchange; or,
- X
- X b) Accompany it with a written offer, valid for at least three
- X years, to give any third party, for a charge no more than your
- X cost of physically performing source distribution, a complete
- X machine-readable copy of the corresponding source code, to be
- X distributed under the terms of Sections 1 and 2 above on a medium
- X customarily used for software interchange; or,
- X
- X c) Accompany it with the information you received as to the offer
- X to distribute corresponding source code. (This alternative is
- X allowed only for noncommercial distribution and only if you
- X received the program in object code or executable form with such
- X an offer, in accord with Subsection b above.)
- X
- XThe source code for a work means the preferred form of the work for
- Xmaking modifications to it. For an executable work, complete source
- Xcode means all the source code for all modules it contains, plus any
- Xassociated interface definition files, plus the scripts used to
- Xcontrol compilation and installation of the executable. However, as a
- Xspecial exception, the source code distributed need not include
- Xanything that is normally distributed (in either source or binary
- Xform) with the major components (compiler, kernel, and so on) of the
- Xoperating system on which the executable runs, unless that component
- Xitself accompanies the executable.
- X
- XIf distribution of executable or object code is made by offering
- Xaccess to copy from a designated place, then offering equivalent
- Xaccess to copy the source code from the same place counts as
- Xdistribution of the source code, even though third parties are not
- Xcompelled to copy the source along with the object code.
- X
- X 4. You may not copy, modify, sublicense, or distribute the Program
- Xexcept as expressly provided under this License. Any attempt
- Xotherwise to copy, modify, sublicense or distribute the Program is
- Xvoid, and will automatically terminate your rights under this License.
- XHowever, parties who have received copies, or rights, from you under
- Xthis License will not have their licenses terminated so long as such
- Xparties remain in full compliance.
- X
- X 5. You are not required to accept this License, since you have not
- Xsigned it. However, nothing else grants you permission to modify or
- Xdistribute the Program or its derivative works. These actions are
- Xprohibited by law if you do not accept this License. Therefore, by
- Xmodifying or distributing the Program (or any work based on the
- XProgram), you indicate your acceptance of this License to do so, and
- Xall its terms and conditions for copying, distributing or modifying
- Xthe Program or works based on it.
- X
- X 6. Each time you redistribute the Program (or any work based on the
- XProgram), the recipient automatically receives a license from the
- Xoriginal licensor to copy, distribute or modify the Program subject to
- Xthese terms and conditions. You may not impose any further
- Xrestrictions on the recipients' exercise of the rights granted herein.
- XYou are not responsible for enforcing compliance by third parties to
- Xthis License.
- X
- X 7. If, as a consequence of a court judgment or allegation of patent
- Xinfringement or for any other reason (not limited to patent issues),
- Xconditions are imposed on you (whether by court order, agreement or
- Xotherwise) that contradict the conditions of this License, they do not
- Xexcuse you from the conditions of this License. If you cannot
- Xdistribute so as to satisfy simultaneously your obligations under this
- XLicense and any other pertinent obligations, then as a consequence you
- Xmay not distribute the Program at all. For example, if a patent
- Xlicense would not permit royalty-free redistribution of the Program by
- Xall those who receive copies directly or indirectly through you, then
- Xthe only way you could satisfy both it and this License would be to
- Xrefrain entirely from distribution of the Program.
- X
- XIf any portion of this section is held invalid or unenforceable under
- Xany particular circumstance, the balance of the section is intended to
- Xapply and the section as a whole is intended to apply in other
- Xcircumstances.
- X
- XIt is not the purpose of this section to induce you to infringe any
- Xpatents or other property right claims or to contest validity of any
- Xsuch claims; this section has the sole purpose of protecting the
- Xintegrity of the free software distribution system, which is
- Ximplemented by public license practices. Many people have made
- Xgenerous contributions to the wide range of software distributed
- Xthrough that system in reliance on consistent application of that
- Xsystem; it is up to the author/donor to decide if he or she is willing
- Xto distribute software through any other system and a licensee cannot
- Ximpose that choice.
- X
- XThis section is intended to make thoroughly clear what is believed to
- Xbe a consequence of the rest of this License.
- X
- X 8. If the distribution and/or use of the Program is restricted in
- Xcertain countries either by patents or by copyrighted interfaces, the
- Xoriginal copyright holder who places the Program under this License
- Xmay add an explicit geographical distribution limitation excluding
- Xthose countries, so that distribution is permitted only in or among
- Xcountries not thus excluded. In such case, this License incorporates
- Xthe limitation as if written in the body of this License.
- X
- X 9. The Free Software Foundation may publish revised and/or new versions
- Xof the General Public License from time to time. Such new versions will
- Xbe similar in spirit to the present version, but may differ in detail to
- Xaddress new problems or concerns.
- X
- XEach version is given a distinguishing version number. If the Program
- Xspecifies a version number of this License which applies to it and "any
- Xlater version", you have the option of following the terms and conditions
- Xeither of that version or of any later version published by the Free
- XSoftware Foundation. If the Program does not specify a version number of
- Xthis License, you may choose any version ever published by the Free Software
- XFoundation.
- X
- X 10. If you wish to incorporate parts of the Program into other free
- Xprograms whose distribution conditions are different, write to the author
- Xto ask for permission. For software which is copyrighted by the Free
- XSoftware Foundation, write to the Free Software Foundation; we sometimes
- Xmake exceptions for this. Our decision will be guided by the two goals
- Xof preserving the free status of all derivatives of our free software and
- Xof promoting the sharing and reuse of software generally.
- X
- X NO WARRANTY
- X
- X 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
- XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
- XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
- XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
- XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
- XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
- XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
- XREPAIR OR CORRECTION.
- X
- X 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
- XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
- XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
- XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
- XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
- XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
- XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
- XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
- XPOSSIBILITY OF SUCH DAMAGES.
- X
- X END OF TERMS AND CONDITIONS
- X
- X Appendix: How to Apply These Terms to Your New Programs
- X
- X If you develop a new program, and you want it to be of the greatest
- Xpossible use to the public, the best way to achieve this is to make it
- Xfree software which everyone can redistribute and change under these terms.
- X
- X To do so, attach the following notices to the program. It is safest
- Xto attach them to the start of each source file to most effectively
- Xconvey the exclusion of warranty; and each file should have at least
- Xthe "copyright" line and a pointer to where the full notice is found.
- X
- X <one line to give the program's name and a brief idea of what it does.>
- X Copyright (C) 19yy <name of author>
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 2 of the License, or
- X (at your option) any later version.
- X
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- XAlso add information on how to contact you by electronic and paper mail.
- X
- XIf the program is interactive, make it output a short notice like this
- Xwhen it starts in an interactive mode:
- X
- X Gnomovision version 69, Copyright (C) 19yy name of author
- X Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- X This is free software, and you are welcome to redistribute it
- X under certain conditions; type `show c' for details.
- X
- XThe hypothetical commands `show w' and `show c' should show the appropriate
- Xparts of the General Public License. Of course, the commands you use may
- Xbe called something other than `show w' and `show c'; they could even be
- Xmouse-clicks or menu items--whatever suits your program.
- X
- XYou should also get your employer (if you work as a programmer) or your
- Xschool, if any, to sign a "copyright disclaimer" for the program, if
- Xnecessary. Here is a sample; alter the names:
- X
- X Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- X `Gnomovision' (which makes passes at compilers) written by James Hacker.
- X
- X <signature of Ty Coon>, 1 April 1989
- X Ty Coon, President of Vice
- X
- XThis General Public License does not permit incorporating your program into
- Xproprietary programs. If your program is a subroutine library, you may
- Xconsider it more useful to permit linking proprietary applications with the
- Xlibrary. If this is what you want to do, use the GNU Library General
- XPublic License instead of this License.
- END_OF_FILE
- if test 17982 -ne `wc -c <'COPYING'`; then
- echo shar: \"'COPYING'\" unpacked with wrong size!
- fi
- # end of 'COPYING'
- fi
- if test -f 'chdir.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'chdir.c'\"
- else
- echo shar: Extracting \"'chdir.c'\" \(9232 characters\)
- sed "s/^X//" >'chdir.c' <<'END_OF_FILE'
- X/*---------------------------------------------------------------------------*
- X *
- X * wish - windowing user friendly shell
- X * --------------------------------------
- X *
- X * (c) Copyright Hellmuth Michaelis 1989 - 1993
- X *
- X * Eggerstedtstr. 28
- X * 22765 Hamburg
- X * Germany
- X *
- X * Tel: +49 / 40 / 384298 (private)
- X * Tel: +49 / 40 / 55903-170 (at work)
- X * e-mail: hm@hcshh.hcs.de
- X *
- X * All rights are reserved except as explicitly granted
- X * by written permission of the author.
- X *
- X * See the file COPYING, distributed with wish, for
- X * restriction and warranty information
- X *
- X * The wildcard matching routine was written by Rich $alz,
- X * <rsalz@bbn.com> and was released to comp.sources.misc, Volume 17.
- X *
- X *---------------------------------------------------------------------------*
- X *
- X * last edit-date: [Mon Aug 30 12:30:23 1993]
- X *
- X * -hm wildcarding cd
- X * -hm resolve "~/"
- X *
- X *----------------------------------------------------------------------------*/
- X
- X#include "wish.h" /* local includes */
- X
- Xstatic char *cd1(char *string);
- Xstatic char *wilddir(char *path, char *wildname);
- X
- X/*---------------------------------------------------------------------------*
- X * change directory, string may contain wildcards
- X *----------------------------------------------------------------------------*/
- Xint cd(char *string)
- X{
- X char *p;
- X
- X if(chdir(string) == 0) /* try out unresolved first */
- X return(0);
- X
- X if((p = cd1(string)) == NULL) /* try to resolve */
- X return(-1);
- X
- X return(chdir(p)); /* try to change dir */
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * return resolved path or NULL if failed
- X *----------------------------------------------------------------------------*/
- Xstatic char *cd1(char *string)
- X{
- X static char left[MAXPATHLEN+1]; /* contains no wildcards */
- X char wname[MAXPATHLEN+1]; /* current wildname to try */
- X
- X register char *sp; /* ptr into string */
- X register char *lp; /* ptr into left */
- X register char *wp; /* ptr into wname */
- X register char *gp; /* gp ptr */
- X
- X left[0] = wname[0] = '\0';
- X
- X sp = string;
- X lp = left;
- X
- X for(;;)
- X {
- X wp = wname;
- X
- X if(*sp == '\0')
- X return(left);
- X
- X if((*sp == '~') && (*(sp+1) == '/'))
- X {
- X lp = left; /* $HOME -> left */
- X gp = envhome; /* $HOME ptr */
- X while(*gp) /* copy $HOME -> left */
- X *lp++ = *gp++; /* new left */
- X *lp++ = '/'; /* terminate left */
- X sp += 2; /* advance sp */
- X continue; /* next segment */
- X }
- X
- X while(*sp && (*sp == '/')) /* check for '/'s */
- X *lp++ = *sp++;
- X
- X while(*sp && (*sp != '/')) /* segment between '/'s -> wname */
- X *wp++ = *sp++;
- X
- X *lp = *wp = '\0'; /* terminate strings */
- X
- X if(strpbrk(wname,WILDCHARS)==NULL) /* check for wildcards */
- X {
- X wp = wname; /* wname start */
- X while(*wp) /* cat wname to left */
- X *lp++ = *wp++;
- X continue; /* next segment */
- X }
- X
- X if((gp = wilddir(left, wname)) == NULL) /* resolve wildcards */
- X return(NULL); /* not found */
- X
- X lp = left; /* resolved -> left */
- X while(*gp)
- X *lp++ = *gp++; /* new left */
- X continue; /* next segment */
- X }
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * check if "wildname" matches any directory name in directory "path"
- X * return concatenated "path" and matched name from dir "
- X *----------------------------------------------------------------------------*/
- Xstatic char *wilddir(char *path, char *wildname)
- X{
- X register struct direct *dp; /* dir access */
- X register DIR *dirp; /* dir access */
- X struct stat fdbuffer; /* stat buffer */
- X static char wtry[MAXPATHLEN+1]; /* try buffer */
- X char rpath[MAXPATHLEN+1]; /* resulting path */
- X
- X strcpy(rpath, path); /* path -> result path */
- X strcat(rpath, "."); /* for readdir */
- X
- X if((dirp = opendir(rpath)) == NULL)
- X return(NULL); /* cannot open directory */
- X
- X for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
- X {
- X if(wildmat(dp->d_name, wildname) == TRUE) /* hit ? */
- X {
- X strcpy(wtry, path); /* pathname */
- X strcat(wtry, dp->d_name); /* matchname */
- X if(stat(wtry, &fdbuffer) < 0)
- X continue; /* not accessible */
- X if(!(S_ISDIR(fdbuffer.st_mode)))/* directory ? */
- X continue; /* no */
- X closedir(dirp); /* close */
- X return(wtry); /* return result */
- X }
- X }
- X closedir(dirp); /* close */
- X return(NULL); /* failed */
- X}
- X
- X
- X/* $Revision: 1.4 $
- X**
- X** Do shell-style pattern matching for ?, \, [], and * characters.
- X** Might not be robust in face of malformed patterns; e.g., "foo[a-"
- X** could cause a segmentation violation. It is 8bit clean.
- X**
- X** Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.
- X** Rich $alz is now <rsalz@bbn.com>.
- X** April, 1991: Replaced mutually-recursive calls with in-line code
- X** for the star character.
- X**
- X** Special thanks to Lars Mathiesen <thorinn@diku.dk> for the ABORT code.
- X** This can greatly speed up failing wildcard patterns. For example:
- X** pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-*
- X** text 1: -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1
- X** text 2: -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1
- X** Text 1 matches with 51 calls, while text 2 fails with 54 calls. Without
- X** the ABORT, then it takes 22310 calls to fail. Ugh. The following
- X** explanation is from Lars:
- X** The precondition that must be fulfilled is that DoMatch will consume
- X** at least one character in text. This is true if *p is neither '*' nor
- X** '\0'.) The last return has ABORT instead of FALSE to avoid quadratic
- X** behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx". With
- X** FALSE, each star-loop has to run to the end of the text; with ABORT
- X** only the last one does.
- X**
- X** Once the control of one instance of DoMatch enters the star-loop, that
- X** instance will return either TRUE or ABORT, and any calling instance
- X** will therefore return immediately after (without calling recursively
- X** again). In effect, only one star-loop is ever active. It would be
- X** possible to modify the code to maintain this context explicitly,
- X** eliminating all recursive calls at the cost of some complication and
- X** loss of clarity (and the ABORT stuff seems to be unclear enough by
- X** itself). I think it would be unwise to try to get this into a
- X** released version unless you have a good test data base to try it out
- X** on.
- X*/
- X
- X /* What character marks an inverted character class? */
- X#define NEGATE_CLASS '!' /* -hm , was '^' */
- X /* Is "*" a common pattern? */
- X#define OPTIMIZE_JUST_STAR
- X /* Do tar(1) matching rules, which ignore a trailing slash? */
- X#undef MATCH_TAR_PATTERN
- X
- X
- X/*
- X** Match text and p, return TRUE, FALSE, or ABORT.
- X*/
- Xstatic int DoMatch(register char *text, register char *p)
- X{
- X register int dolast; /* -hm, was "last" */
- X register int matched;
- X register int reverse;
- X
- X for ( ; *p; text++, p++) {
- X if (*text == '\0' && *p != '*')
- X return ABORT;
- X switch (*p) {
- X case '\\':
- X /* Literal match with following character. */
- X p++;
- X /* FALLTHROUGH */
- X default:
- X if (*text != *p)
- X return FALSE;
- X continue;
- X case '?':
- X /* Match anything. */
- X continue;
- X case '*':
- X while (*++p == '*')
- X /* Consecutive stars act just like one. */
- X continue;
- X if (*p == '\0')
- X /* Trailing star matches everything. */
- X return TRUE;
- X while (*text)
- X if ((matched = DoMatch(text++, p)) != FALSE)
- X return matched;
- X return ABORT;
- X case '[':
- X reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE;
- X if (reverse)
- X /* Inverted character class. */
- X p++;
- X for (dolast = 0400, matched = FALSE; *++p && *p != ']'; dolast = *p)
- X /* This next line requires a good C compiler. */
- X if (*p == '-' ? *text <= *++p && *text >= dolast : *text == *p)
- X matched = TRUE;
- X if (matched == reverse)
- X return FALSE;
- X continue;
- X }
- X }
- X
- X#ifdef MATCH_TAR_PATTERN
- X if (*text == '/')
- X return TRUE;
- X#endif /* MATCH_TAR_ATTERN */
- X return *text == '\0';
- X}
- X
- X
- X/*
- X** User-level routine. Returns TRUE or FALSE.
- X*/
- Xint wildmat(char *text, char *p)
- X{
- X#ifdef OPTIMIZE_JUST_STAR
- X if (p[0] == '*' && p[1] == '\0')
- X return TRUE;
- X#endif /* OPTIMIZE_JUST_STAR */
- X return DoMatch(text, p) == TRUE;
- X}
- X
- X
- X
- X#ifdef TEST
- X#include <stdio.h>
- X
- X/* Yes, we use gets not fgets. Sue me. */
- Xextern char *gets();
- X
- X
- Xmain()
- X{
- X char p[80];
- X char text[80];
- X
- X printf("Wildmat tester. Enter pattern, then strings to test.\n");
- X printf("A blank line gets prompts for a new pattern; a blank pattern\n");
- X printf("exits the program.\n");
- X
- X for ( ; ; ) {
- X printf("\nEnter pattern: ");
- X (void)fflush(stdout);
- X if (gets(p) == NULL || p[0] == '\0')
- X break;
- X for ( ; ; ) {
- X printf("Enter text: ");
- X (void)fflush(stdout);
- X if (gets(text) == NULL)
- X exit(0);
- X if (text[0] == '\0')
- X /* Blank line; go back and get a new pattern. */
- X break;
- X printf(" %s\n", wildmat(text, p) ? "YES" : "NO");
- X }
- X }
- X
- X exit(0);
- X /* NOTREACHED */
- X}
- X#endif /* TEST */
- X
- X/*---------------------------------- EOF -------------------------------------*/
- END_OF_FILE
- if test 9232 -ne `wc -c <'chdir.c'`; then
- echo shar: \"'chdir.c'\" unpacked with wrong size!
- fi
- # end of 'chdir.c'
- fi
- if test -f 'history.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'history.c'\"
- else
- echo shar: Extracting \"'history.c'\" \(14577 characters\)
- sed "s/^X//" >'history.c' <<'END_OF_FILE'
- X/*---------------------------------------------------------------------------*
- X *
- X * wish - windowing user friendly shell
- X * ------------------------------------
- X *
- X * Copyright (c) 1988-1993 Hellmuth Michaelis
- X *
- X * Eggerstedtstr. 28
- X * 22765 Hamburg
- X * Germany
- X *
- X * Tel: +49 / 40 / 384298 (private)
- X * Tel: +49 / 40 / 55903-170 (at work)
- X * e-mail: hm@hcshh.hcs.de
- X *
- X * --------oOo--------
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 2 of the License, or
- X * (at your option) any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X *---------------------------------------------------------------------------*
- X *
- X * last edit-date: [Wed Sep 22 13:28:09 1993]
- X *
- X * -hm history on commandline
- X * -hm integrating line handling from terminal.c from my sh
- X * -hm debugging line editor
- X *
- X *---------------------------------------------------------------------------*/
- X
- X#include "wish.h" /* local includes */
- X
- Xstatic char overstrike; /* overstrike mode */
- Xstatic char kbuf[HISLNLEN]; /* kill buffer */
- Xstatic int kbuf_init = 0; /* static kill buffer */
- Xstatic char *beg; /* line start (first char on line) */
- Xstatic char *pnt; /* next insertion position (cursor) */
- Xstatic char *end; /* line end (first free pos on line) */
- Xstatic char *sbeg; /* first character on screen */
- Xstatic int lmax; /* maximum charcount requested from caller */
- X
- Xstatic void pmstr(char *); /* forward decl */
- Xstatic void pnstr(int, char *);
- Xvoid dis_hist(void);
- X
- X/*---------------------------------------------------------------------------*
- X * return current (cursor) column
- X *---------------------------------------------------------------------------*/
- Xint curcol(void)
- X{
- X return((int)(pnt - sbeg));
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * return true, if commandline empty ( == operate on file window on CR )
- X *---------------------------------------------------------------------------*/
- Xint cr_on_files(void)
- X{
- X return((int)(beg == end));
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * init commandline history system
- X *---------------------------------------------------------------------------*/
- Xvoid init_history(void)
- X{
- X overstrike = 0; /* insert is default */
- X
- X cur_his = 0; /* current history pointer */
- X strcpy(cbuff,hislines[cur_his]);
- X
- X sbeg = cbuff; /* screen begin at start of buffer */
- X beg = cbuff + strlen(cbuff); /* position beg after prompt */
- X pnt = end = beg; /* point = end = buffer begin */
- X
- X kbuf[0] = '\0'; /* init kill - buffer */
- X kbuf_init = 1; /* static kbuf */
- X
- X lmax = HISLNLEN-1; /* max line length */
- X
- X wmove(cmnd_w,C_LINE,0); /* beg of line */
- X waddstr(cmnd_w, cbuff); /* write prompt */
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * save current commandline to history stack
- X *---------------------------------------------------------------------------*/
- Xvoid save_line(void)
- X{
- X strncpy(hislines[cur_his],cbuff,HISLNLEN-1);
- X if(cur_his == HISLINES-1)
- X cur_his = 0;
- X else
- X cur_his++;
- X hislines[cur_his][3] = '\0';
- X dis_hist();
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * get previous history line
- X *---------------------------------------------------------------------------*/
- Xvoid prev_line(void)
- X{
- X if(cur_his == 0)
- X cur_his = HISLINES-1;
- X else
- X cur_his--;
- X
- X dis_hist();
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * get next history line
- X *---------------------------------------------------------------------------*/
- Xvoid next_line(void)
- X{
- X if(cur_his == HISLINES-1)
- X cur_his = 0;
- X else
- X cur_his++;
- X
- X dis_hist();
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * valid new line from history stack, display it
- X *---------------------------------------------------------------------------*/
- Xvoid dis_hist(void)
- X{
- X strncpy(cbuff,hislines[cur_his],HISLNLEN-1);
- X
- X if((strlen(cbuff)) < COLS)
- X { /* new line will fit onto screen */
- X wmove(cmnd_w,C_LINE,0); /* move to start of line */
- X wclrtoeol(cmnd_w); /* clear line */
- X wmove(cmnd_w,C_LINE,0); /* move to start of line */
- X waddstr(cmnd_w, cbuff); /* write new line */
- X sbeg = cbuff; /* new screen begin */
- X }
- X else
- X { /* line will not fit onto screen, search end & write new */
- X wmove(cmnd_w,C_LINE,0); /* start of line */
- X wclrtoeol(cmnd_w); /* clear to end of line */
- X sbeg = cbuff; /* start of buffer */
- X while((strlen(sbeg) + 1) > COLS) /* find segment */
- X sbeg += COLS/2; /* start */
- X waddstr(cmnd_w, sbeg); /* write last segment */
- X }
- X pnt = end = (cbuff + strlen(cbuff));
- X beg = cbuff + 3; /* position beg after prompt */
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * move cursor forward
- X *---------------------------------------------------------------------------*/
- Xvoid right_line(void)
- X{
- X if(pnt < end) /* something to move ? */
- X {
- X pnt++; /* next char */
- X if(pnt > (sbeg + COLS)) /* moving on screen ? */
- X {
- X sbeg += COLS/2; /* new screen begin */
- X wmove(cmnd_w,C_LINE,0); /* start of screen */
- X wclrtoeol(cmnd_w); /* clear line */
- X pmstr(sbeg); /* write new segment */
- X }
- X }
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * move cursor back one character
- X *---------------------------------------------------------------------------*/
- Xvoid left_line(void)
- X{
- X if(pnt > beg) /* allowed to move ?? */
- X {
- X pnt--; /* prev char */
- X if(pnt < sbeg) /* move on screen ?? */
- X {
- X sbeg -= COLS/2; /* back 1/2 length */
- X wmove(cmnd_w,C_LINE,0); /* start of screen */
- X wclrtoeol(cmnd_w); /* clear line */
- X pmstr(sbeg); /* print this part of buffer */
- X }
- X }
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * append / insert / overstrike a (printable) character
- X *---------------------------------------------------------------------------*/
- Xint cmdline(int c)
- X{
- X if((end-beg) < lmax) /* space in buffer ? */
- X {
- X if(pnt == end) /************ append **********/
- X {
- X *pnt++ = c; /* store char */
- X end++; /* new end ptr */
- X *end = '\0'; /* new terminator */
- X
- X if((end-sbeg+1) > COLS)
- X {
- X sbeg += COLS/2;
- X wmove(cmnd_w,C_LINE,0);
- X wclrtoeol(cmnd_w);
- X waddstr(cmnd_w, sbeg);
- X }
- X else
- X {
- X waddch(cmnd_w,c); /* echo char */
- X }
- X }
- X else if(!overstrike) /************** insert **********/
- X {
- X register char *p;
- X register char *q;
- X
- X p = end-1; /* last char */
- X q = end; /* last char + 1 */
- X while(q > pnt) /* shift right buffer */
- X *q-- = *p--;
- X
- X *pnt = c; /* store chr into gap */
- X end++; /* increment end ptr */
- X *end = '\0'; /* new terminator */
- X
- X if( (pnt+1) > (sbeg + COLS)) /* scroll right ? */
- X {
- X sbeg += COLS/2; /* new screen beg */
- X }
- X wmove(cmnd_w,C_LINE,0); /* start of line */
- X pmstr(sbeg); /* print string */
- X pnt++; /* new point */
- X }
- X else /************** overstrike ****************/
- X {
- X *pnt++ = c; /* store char */
- X
- X if((pnt-sbeg+1) > COLS)
- X {
- X sbeg += COLS/2;
- X wmove(cmnd_w,C_LINE,0);
- X wclrtoeol(cmnd_w);
- X pmstr(sbeg);
- X }
- X else
- X {
- X waddch(cmnd_w,c); /* echo char */
- X }
- X }
- X return(GOOD);
- X }
- X else
- X {
- X flash(); /* no no .. */
- X return(BAD); /* don't accept it */
- X }
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * delete character left of cursor
- X *---------------------------------------------------------------------------*/
- Xvoid handlebs(void)
- X{
- X register char *p;
- X register char *q;
- X
- X if(pnt == beg) /* at start of buffer ? */
- X return; /* yes */
- X
- X q = pnt; /* next char */
- X pnt--; /* point backward */
- X p = pnt; /* this char */
- X while(q < end) /* shift left buffer */
- X *p++ = *q++;
- X end--; /* new end pointer */
- X *end = '\0'; /* new end terminator */
- X
- X if(pnt < sbeg) /* moved into previous segment ? */
- X {
- X sbeg -= COLS/2; /* new segment start */
- X }
- X wmove(cmnd_w,C_LINE,0); /* start of screen line */
- X wclrtoeol(cmnd_w); /* clear line */
- X pmstr(sbeg); /* write segment */
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * delete character under cursor
- X *---------------------------------------------------------------------------*/
- Xvoid del_char(void)
- X{
- X register char *p;
- X register char *q;
- X
- X if(pnt == end) /* at start of buffer ? */
- X return; /* yes */
- X
- X p = pnt; /* current char */
- X q = pnt+1; /* next char */
- X
- X while(q < end) /* shift left buffer */
- X *p++ = *q++;
- X
- X end--; /* new end pointer */
- X *end = '\0'; /* new end terminator */
- X
- X wmove(cmnd_w,C_LINE,0); /* start of screen line */
- X wclrtoeol(cmnd_w); /* clear line */
- X pmstr(sbeg); /* write new segment */
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * print string, maximum length is COLS
- X *---------------------------------------------------------------------------*/
- Xstatic void pmstr(char *str)
- X{
- X char buf[256];
- X register int i = 0;
- X
- X while((*str) && (i < COLS))
- X buf[i++] = *str++;
- X buf[i] = '\0';
- X waddstr(cmnd_w, buf);
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * print string, maximum length parameter <n>
- X *---------------------------------------------------------------------------*/
- Xstatic void pnstr(int n, char *str)
- X{
- X char buf[256];
- X register int i = 0;
- X
- X while((*str) && (i < n))
- X buf[i++] = *str++;
- X buf[i] = '\0';
- X waddstr(cmnd_w, buf);
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * delete from cursor to end of line
- X *---------------------------------------------------------------------------*/
- Xvoid clear_toeol(void)
- X{
- X strcpy(kbuf, pnt); /* save to kill buffer */
- X wclrtoeol(cmnd_w); /* clear line */
- X end = pnt; /* new end ptr */
- X *end = '\0'; /* terminate line */
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * move cursor to end of line
- X *---------------------------------------------------------------------------*/
- Xvoid eol_line(void)
- X{
- X if(pnt == end) /* already at end ? */
- X return; /* yes */
- X
- X if((strlen(cbuff) < COLS) && (sbeg == cbuff))
- X {
- X pnt = end; /* set point to end */
- X }
- X else
- X {
- X wmove(cmnd_w,C_LINE,0); /* start of line */
- X wclrtoeol(cmnd_w); /* clear to end of line */
- X sbeg = cbuff; /* start of buffer */
- X while((strlen(sbeg) + 1) > COLS) /* find segment */
- X sbeg += COLS/2; /* start */
- X waddstr(cmnd_w, sbeg); /* write last segment */
- X pnt = end; /* new point */
- X }
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * move cursor to begin of line
- X *---------------------------------------------------------------------------*/
- Xvoid bol_line(void)
- X{
- X if(pnt == beg) /* already at begin of buffer */
- X return; /* nothing to do ! */
- X
- X pnt = beg; /* point = buffer start */
- X
- X if(sbeg != cbuff) /* not in first screen segment */
- X {
- X wmove(cmnd_w,C_LINE,0); /* cursor -> start of screen */
- X wclrtoeol(cmnd_w); /* clear to end of line */
- X pmstr(cbuff); /* write from start of buffer */
- X sbeg = cbuff; /* screen begin = buffer start */
- X }
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * yank text from kill-buffer to current point
- X *---------------------------------------------------------------------------*/
- Xvoid yank(void)
- X{
- X if(kbuf[0] == '\0') /* kill buffer empty ? */
- X return; /* yes, exit */
- X
- X if((end - beg) >= lmax) /* space in buffer ? */
- X { /* no... */
- X if((overstrike) && (pnt == end)) /* perhaps overstr in the middle ? */
- X return; /* no... */
- X if(!overstrike) /* insert / append ? */
- X return; /* yes */
- X }
- X
- X /* here if either space in buffer or overwrite not at end */
- X
- X if(pnt == end) /************ append **********/
- X {
- X /* append kill buffer to buffer, observe buffer max length */
- X
- X strncat(cbuff, kbuf, lmax);
- X end = cbuff + strlen(cbuff);
- X if((end-sbeg+1) > COLS)
- X {
- X while((end-sbeg+1) > COLS)
- X sbeg += COLS/2;
- X wmove(cmnd_w,C_LINE,0);
- X wclrtoeol(cmnd_w);
- X waddstr(cmnd_w, sbeg); /* write whole new segment */
- X }
- X else
- X {
- X waddstr(cmnd_w, pnt); /* write new end */
- X }
- X pnt = end; /* set new pnt */
- X }
- X else if(!overstrike) /************** insert **********/
- X {
- X char tail[HISLNLEN]; /* temp storage */
- X register int i; /* gp... */
- X register char *p = pnt; /* save point pos */
- X
- X strcpy(tail, pnt); /* save string frm point on */
- X strncpy(pnt, kbuf, lmax); /* insert up to max */
- X pnt = cbuff + strlen(cbuff);
- X strcat(pnt, tail); /* append saved tail */
- X end = cbuff + strlen(cbuff);
- X
- X if((pnt-sbeg+1) > COLS)
- X { /* new point is outside current segment */
- X while((pnt-sbeg+1) > COLS)
- X sbeg += COLS/2;
- X wmove(cmnd_w,C_LINE,0);
- X wclrtoeol(cmnd_w);
- X pmstr(sbeg); /* print string */
- X }
- X else
- X { /* new point is inside current segment */
- X if((strlen(sbeg)) < COLS) /* line > than screen ? */
- X i = (sbeg + strlen(sbeg)) - p; /* no */
- X else
- X i = (sbeg + COLS) - p; /* yes */
- X pnstr(i, p); /* new tail */
- X p += i;
- X while(p-- > pnt)
- X wmove(cmnd_w, C_LINE, (curcol()-1));
- X }
- X }
- X else /************** overstrike ****************/
- X {
- X register int j = lmax;
- X register char *k = kbuf;
- X
- X while(j-- && *k)
- X *pnt++ = *k++; /* copy kbuf over buffer */
- X
- X if(pnt > end) /* buffer grown bigger ? */
- X {
- X end = pnt; /* set new end ptr */
- X *end = '\0'; /* terminate buffer */
- X }
- X
- X if((pnt-sbeg+1) > COLS)
- X { /* new point is outside current segment */
- X while((pnt-sbeg+1) > COLS)
- X sbeg += COLS/2;
- X wmove(cmnd_w,C_LINE,0);
- X wclrtoeol(cmnd_w);
- X pmstr(sbeg); /* print string */
- X }
- X else
- X { /* new point is inside current segment */
- X waddstr(cmnd_w, kbuf);
- X }
- X }
- X}
- X
- X/*----------------------- E O F -------------------------------------------*/
- END_OF_FILE
- if test 14577 -ne `wc -c <'history.c'`; then
- echo shar: \"'history.c'\" unpacked with wrong size!
- fi
- # end of 'history.c'
- fi
- if test -f 'wish.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'wish.c'\"
- else
- echo shar: Extracting \"'wish.c'\" \(14397 characters\)
- sed "s/^X//" >'wish.c' <<'END_OF_FILE'
- X/*---------------------------------------------------------------------------*
- X *
- X * wish - windowing user friendly shell
- X * ------------------------------------
- X *
- X * Copyright (c) 1988-1993 Hellmuth Michaelis
- X *
- X * Eggerstedtstr. 28
- X * 22765 Hamburg
- X * Germany
- X *
- X * Tel: +49 / 40 / 384298 (private)
- X * Tel: +49 / 40 / 55903-170 (at work)
- X * e-mail: hm@hcshh.hcs.de
- X *
- X * --------oOo--------
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 2 of the License, or
- X * (at your option) any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X *---------------------------------------------------------------------------*
- X *
- X * Last Edit-Date: [Mon Aug 30 19:59:18 1993]
- X *
- X * -hm converting to curses and multiwindows
- X * -hm general cleanup ....
- X * -hm adding a close-current-dir function and fkey
- X * -hm adding history to command line
- X * -hm default display attribs on
- X * -hm changing coomandline control to emacs-commands
- X * -hm vt220 support, housekeeping
- X * -hm show time in header
- X * -hm try to preserve current position after command
- X * -hm backspace char from termio struct
- X * -hm porting to 386BSD
- X * -hm show links flag
- X * -hm config file processing "$HOME/.wishrc"
- X * -hm add / subtract option processing
- X * -hm exit() -> fatal() changed
- X * -hm hpterm / config menu
- X * -hm fixed delete character bug
- X * -hm fkey label structures
- X * -hm ESC,ESC filename completition
- X * -hm GNU copyleft
- X *
- X *----------------------------------------------------------------------------*/
- X
- X#define MAIN /* declare variables into this file */
- X
- X#include "wish.h" /* everything we want */
- X#include "control.h" /* control-characters */
- X
- X/*---------------------------------------------------------------------------*
- X * main loop
- X *---------------------------------------------------------------------------*/
- Xint main (int argc, char *argv[])
- X{
- X char c; /* just for argument processing */
- X int i; /* gp int */
- X int kchar; /* character from keyboard */
- X int optmode; /* add (1) or subtract (0) option mode */
- X errorflag = 0; /* no error yet */
- X
- X /* first - set up defaults from environment */
- X
- X if((envhome = getenv("HOME")) == NULL)
- X {
- X fprintf(stderr, "\n Environment variable \"HOME\" not set!\n");
- X exit(1);
- X }
- X
- X if((envmore = getenv("PAGER")) == NULL)
- X {
- X envmore = "more"; /* default pager for file display */
- X }
- X
- X if((envedit = getenv("EDITOR")) == NULL)
- X {
- X if((envedit = getenv("VISUAL")) == NULL)
- X {
- X envedit = "vi"; /* default editor */
- X }
- X }
- X
- X if((term_string = getenv("TERM")) == NULL)
- X {
- X fprintf(stderr,"\nwish: environment variable \"TERM\" undefined, cannot run!\n");
- X exit(1);
- X }
- X
- X /* init local changable string buffers & pointers */
- X
- X strcpy(opt_edit, envedit); /* cp from env to local buffer */
- X strcpy(opt_more, envmore); /* cp from env to local buffer */
- X strcpy(opt_wild, "*"); /* init wildcard buffer ... */
- X
- X /* second - configure ourselves from users .wishrc */
- X
- X readrc(); /* read $HOME/.wishrc */
- X
- X /* adjust for misconfigured wildcards */
- X
- X if(opt_wild && (strpbrk(opt_wild,WILDCHARS)==NULL))
- X opt_wildon = 0;
- X
- X /* third - configure ourselves from command line parms */
- X
- X while((--argc > 0) && ( ((*++argv)[0] == '-') || ((*argv)[0] == '+')) )
- X {
- X if((*argv)[0] == '-')
- X optmode = 0;
- X else
- X optmode = 1;
- X
- X c = *++argv[0];
- X
- X while(c)
- X {
- X switch(c)
- X {
- X case 'a': /* attributes line */
- X if(optmode)
- X opt_attrib = 1;
- X else
- X opt_attrib = 0;
- X break;
- X
- X case 'd': /* initial preserve dir when cd .. */
- X if(optmode)
- X opt_preserve = 1;
- X else
- X opt_preserve = 0;
- X break;
- X
- X case 'f': /* NO f-key labels on non-hp terminals */
- X if(optmode)
- X opt_labels = 1;
- X else
- X opt_labels = 0;
- X break;
- X
- X case 'l': /* show links not files */
- X if(optmode)
- X opt_links = 1;
- X else
- X opt_links = 0;
- X break;
- X
- X case 'p': /* display current dir in file window */
- X if(optmode)
- X opt_point = 1;
- X else
- X opt_point = 0;
- X break;
- X
- X case 'r': /* press return to continue */
- X if(optmode)
- X opt_return = 1;
- X else
- X opt_return = 0;
- X break;
- X
- X case 'w': /* enable wildcards */
- X if(optmode)
- X opt_wildon = 1;
- X else
- X opt_wildon = 0;
- X break;
- X
- X case 'c': /* cdrom mode */
- X if(optmode)
- X opt_cdrom = 1;
- X else
- X opt_cdrom = 0;
- X break;
- X
- X case 'C': /* cdrom progs->files */
- X if(optmode)
- X opt_cdnoprog = 1;
- X else
- X opt_cdnoprog = 0;
- X break;
- X
- X case 'n': /* display dot-filenames */
- X if(optmode)
- X opt_dotnames = 1;
- X else
- X opt_dotnames = 0;
- X break;
- X
- X default:
- X fprintf(stderr,"\nwish: illegal option -%c",c);
- X
- X case '?':
- X usage(); /* no return */
- X }
- X }
- X }
- X
- X if(opt_attrib == 0) /* if no attrib line, */
- X opt_links = 0; /* no link detection necessary */
- X
- X /* allocate memory for history */
- X
- X for(i=0; i < HISLINES; i++)
- X {
- X if((hislines[i] = (char *)malloc(HISLNLEN)) == NULL)
- X {
- X fprintf(stderr,"\nwish: history malloc failed, exit ...\n");
- X exit(1);
- X }
- X sprintf(hislines[i],"%02d>",i); /* write prompt */
- X }
- X
- X cur_fktab = &sys_keys; /* current fkey label table */
- X
- X init_header(); /* initialize header string */
- X init_time(); /* display time init */
- X init_screen(); /* initialize screen */
- X init_flabels(); /* init fkey-labels */
- X init_history(); /* init commandline history */
- X init_files(PRES_NO, NULL); /* read current directory */
- X attribs(1); /* display attributes */
- X update_all(); /* force first screen-update */
- X
- X switch(termtype) /* hpux curses workaround */
- X { /* for 2nd bug ..... */
- X case TERM_VT1: /* force header update on */
- X case TERM_VT2: /* dec terminals 2 times */
- X case TERM_VT3: /* to display inverse!!!! */
- X case TERM_PCVT:
- X wmove(cmnd_w, C_HEAD, 0);
- X waddstr(cmnd_w,headerline);
- X wrefresh(cmnd_w);
- X header();
- X break;
- X }
- X
- X wmove(cmnd_w, C_LINE, curcol());/* cursor to command window */
- X wrefresh(cmnd_w); /* update command window */
- X
- X bschar = erasechar(); /* get backspace char */
- X
- X for(;;)
- X {
- X kchar = getch(); /* get char */
- X
- X clrerror(); /* if error line in header, clear ! */
- X
- X if(((kchar >= 0x20) && (kchar <= 0x7e)) ||
- X ((kchar >= 0x80) && (kchar <= 0xff)))
- X {
- X /* printable char's to commandline */
- X
- X cmdline(kchar);
- X wmove(cmnd_w, C_LINE, curcol());
- X wrefresh(cmnd_w);
- X continue;
- X }
- X else if(kchar == bschar) /* backspace */
- X {
- X handlebs();
- X }
- X else /* special keys = special actions */
- X {
- X switch(kchar)
- X {
- X case CR:
- X handlecr();
- X update_files();
- X break;
- X
- X case KEY_DC: /* delete last char */
- X del_char();
- X break;
- X
- X case KEY_BACKSPACE:
- X handlebs();
- X break;
- X
- X case KEY_RIGHT: /* right move cursor */
- X case TAB:
- X move_right();
- X update_files();
- X break;
- X
- X case KEY_LEFT: /* left move cursor */
- X case KEY_BTAB:
- X move_left();
- X update_files();
- X break;
- X
- X case KEY_UP: /* up-move cursor */
- X move_up();
- X update_files();
- X break;
- X
- X case KEY_DOWN: /* down-move cursor */
- X move_down();
- X update_files();
- X break;
- X
- X case KEY_HOME: /* move cursor to first dir */
- X move_home();
- X update_files();
- X break;
- X
- X case KEY_LL: /* move cursor to last file */
- X move_hmdn();
- X update_files();
- X break;
- X
- X case KEY_NPAGE: /* next/previous page */
- X next_page();
- X update_files();
- X break;
- X
- X case KEY_PPAGE: /* next/previous page */
- X prev_page();
- X update_files();
- X break;
- X
- X case KEY_F(1): /* function key 1 */
- X edit_current();
- X break;
- X
- X case KEY_F(2): /* function key 2 */
- X name_echo();
- X break;
- X
- X case KEY_F(3): /* function key 3 */
- X help();
- X update_files();
- X break;
- X
- X case KEY_F(4): /* function key 4 */
- X config();
- X break;
- X
- X case KEY_F(5): /* function key 5 */
- X tag_current(cur_file);
- X move_right();
- X update_files();
- X break;
- X
- X case KEY_F(6): /* function key 6 */
- X untag_all();
- X update_files();
- X break;
- X
- X case KEY_F(7): /* function key 7 */
- X break;
- X
- X case KEY_F(8): /* function key 8 */
- X close_cdir();
- X update_files();
- X break;
- X
- X case CNTRL_F: /* right move cursor */
- X right_line();
- X break;
- X
- X case CNTRL_B: /* left move cursor */
- X left_line();
- X break;
- X
- X case CNTRL_P: /* up-move cursor */
- X prev_line();
- X break;
- X
- X case CNTRL_N: /* down-move cursor */
- X next_line();
- X break;
- X
- X case CNTRL_D:
- X if(cr_on_files())
- X {
- X move(LINES,COLS-1); /* last display position */
- X free_list(); /* free memory */
- X fini_flabels(); /* normal fkey-labels */
- X endwin(); /* normalize screen */
- X putchar('\n'); /* newline */
- X exit(0);
- X }
- X del_char();
- X break;
- X
- X case CNTRL_K: /* clear to eol */
- X clear_toeol();
- X break;
- X
- X case CNTRL_Y: /* yank kill buffer */
- X yank();
- X break;
- X
- X case CNTRL_A: /* begin of line */
- X bol_line();
- X break;
- X
- X case CNTRL_E: /* end of line */
- X eol_line();
- X break;
- X
- X case CNTRL_L: /* refresh */
- X touchwin(curscr);
- X wrefresh(curscr);
- X break;
- X
- X case ESC:
- X kchar = getch(); /* get char */
- X switch(kchar)
- X {
- X case '1': /* function key 1 */
- X edit_current();
- X break;
- X
- X case '2': /* function key 2 */
- X name_echo();
- X break;
- X
- X case '3': /* function key 3 */
- X help();
- X update_files();
- X break;
- X
- X case '4': /* function key 4 */
- X config();
- X break;
- X
- X case '5': /* function key 5 */
- X tag_current(cur_file);
- X move_right();
- X update_files();
- X break;
- X
- X case '6': /* function key 6 */
- X untag_all();
- X update_files();
- X break;
- X
- X case '7': /* function key 7 */
- X break;
- X
- X case '8': /* function key 8 */
- X close_cdir();
- X update_files();
- X break;
- X
- X case 'n':
- X case 'N':
- X next_page();
- X update_files();
- X break;
- X
- X case 'p':
- X case 'P':
- X prev_page();
- X update_files();
- X break;
- X
- X case ESC: /* filename completition */
- X complete();
- X break;
- X }
- X }
- X }
- X wmove(cmnd_w, C_LINE, curcol());
- X wrefresh(cmnd_w);
- X }
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * initialize curses and window dimensions
- X *---------------------------------------------------------------------------*/
- Xvoid init_screen(void) /* initialize everything */
- X{
- X int attrpos;
- X
- X initscr(); /* curses init */
- X nonl(); /* optimize */
- X raw(); /* raw input */
- X noecho(); /* do not echo input */
- X idlok(stdscr,TRUE); /* use insert/delete */
- X keypad(stdscr,TRUE); /* use special keys */
- X meta(stdscr,TRUE); /* use 8-bit chars */
- X
- X set_termtype(); /* init terminal dep. stuff */
- X
- X if((cmnd_w = newwin(C_HEIGHT, COLS, 0, 0)) == NULL)
- X fatal("cannot create command window");
- X
- X fileheight = LINES-C_HEIGHT;
- X
- X if(opt_labels)
- X {
- X if((flbl_w = newwin(1, COLS, LINES-1, 0)) == NULL)
- X fatal("cannot create fkey-label window");
- X fileheight--;
- X }
- X
- X if(opt_attrib)
- X {
- X fileheight -= 2;
- X attrpos = C_HEIGHT+fileheight;
- X
- X if((attr_w = newwin(2, COLS, attrpos, 0)) == NULL)
- X fatal("cannot create attribute window");
- X }
- X
- X if((fst_w = newwin(2, COLS, C_HEIGHT, 0)) == NULL)
- X fatal("cannot create file status window");
- X
- X fileheight -= 2;
- X
- X if((file_w = newwin(fileheight, COLS, C_HEIGHT+2, 0)) == NULL)
- X fatal("cannot create file window");
- X
- X header(); /* print headerline */
- X clearok(curscr,TRUE);
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * refresh all windows
- X *---------------------------------------------------------------------------*/
- Xvoid update_all(void)
- X{
- X wnoutrefresh(cmnd_w);
- X wnoutrefresh(fst_w);
- X touchwin(file_w); /* after cur_blink() */
- X wnoutrefresh(file_w);
- X if(opt_attrib)
- X wnoutrefresh(attr_w);
- X if(opt_labels)
- X wnoutrefresh(flbl_w);
- X doupdate();
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * refresh file window and attrib window
- X *---------------------------------------------------------------------------*/
- Xvoid update_files(void)
- X{
- X wnoutrefresh(file_w);
- X if(opt_attrib)
- X wnoutrefresh(attr_w);
- X if(opt_labels)
- X wnoutrefresh(flbl_w);
- X doupdate();
- X}
- X
- X/*---------------------------------------------------------------------------*
- X * find out terminal-type and initialize terminal specific things
- X *---------------------------------------------------------------------------*/
- Xvoid set_termtype(void)
- X{
- X static char initvt[] = { ESC, ')', '0', '\0'};
- X
- X if(ceol_standout_glitch) /* HP-Terminal */
- X {
- X opt_labels = 0; /* no virtual fkey-labels */
- X if(!strcmp(term_string,"hpterm")) /* X11 hpterm */
- X termtype = TERM_HPX;
- X else
- X termtype = TERM_HP;
- X }
- X
- X else if(!strncmp(term_string,"vt1",3)) /* DEC VT1xx ?? */
- X {
- X opt_labels = 1; /* virtual fkey-labels */
- X termtype = TERM_VT1;
- X }
- X
- X else if(!strncmp(term_string,"vt220",5))/* DEC VT220 ?? */
- X {
- X opt_labels = 1; /* virtual fkey-labels */
- X write(2, initvt, 3);
- X termtype = TERM_VT2;
- X }
- X
- X else if(!strncmp(term_string,"vt320",5))/* DEC VT320 ?? */
- X {
- X opt_labels = 1; /* virtual fkey-labels */
- X write(2, initvt, 3);
- X termtype = TERM_VT3;
- X }
- X
- X else if(!strncmp(term_string,"pcvt",4)) /* 386BSD pcvt ?? */
- X {
- X opt_labels = 0; /* real fkey-labels */
- X write(2, initvt, 3);
- X termtype = TERM_PCVT;
- X }
- X
- X else /* dumb thing .. */
- X {
- X termtype = TERM_DUMB;
- X }
- X}
- X
- X/*---------------------------------- EOF ----------------------------------*/
- END_OF_FILE
- if test 14397 -ne `wc -c <'wish.c'`; then
- echo shar: \"'wish.c'\" unpacked with wrong size!
- fi
- # end of 'wish.c'
- fi
- echo shar: End of archive 2 \(of 4\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 3 4 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 4 archives.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-