home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / cwish / part02 < prev    next >
Encoding:
Text File  |  1993-09-22  |  59.4 KB  |  1,853 lines

  1. Newsgroups: comp.sources.misc
  2. From: hm@hcshh.hcs.de (Hellmuth Michaelis)
  3. Subject: v39i098:  cwish - Window Shell / Filemanager v1.00, Part02/04
  4. Message-ID: <1993Sep22.161434.25876@sparky.sterling.com>
  5. X-Md4-Signature: 225384db6f2c7c0d521458fe5ee974a8
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Reply-To: hm@hcshh.hcs.de
  8. Organization: HCS Hanseatischer Computerservice GmbH
  9. Date: Wed, 22 Sep 1993 16:14:34 GMT
  10. Approved: kent@sparky.sterling.com
  11.  
  12. Submitted-by: hm@hcshh.hcs.de (Hellmuth Michaelis)
  13. Posting-number: Volume 39, Issue 98
  14. Archive-name: cwish/part02
  15. Environment: HP-UX, 386BSD, NETBSD, ANSI-C, SYSV-CURSES
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  COPYING chdir.c history.c wish.c
  22. # Wrapped by kent@sparky on Wed Sep 22 10:49:57 1993
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 2 (of 4)."'
  26. if test -f 'COPYING' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'COPYING'\"
  28. else
  29.   echo shar: Extracting \"'COPYING'\" \(17982 characters\)
  30.   sed "s/^X//" >'COPYING' <<'END_OF_FILE'
  31. X            GNU GENERAL PUBLIC LICENSE
  32. X               Version 2, June 1991
  33. X
  34. X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  35. X                          675 Mass Ave, Cambridge, MA 02139, USA
  36. X Everyone is permitted to copy and distribute verbatim copies
  37. X of this license document, but changing it is not allowed.
  38. X
  39. X                Preamble
  40. X
  41. X  The licenses for most software are designed to take away your
  42. Xfreedom to share and change it.  By contrast, the GNU General Public
  43. XLicense is intended to guarantee your freedom to share and change free
  44. Xsoftware--to make sure the software is free for all its users.  This
  45. XGeneral Public License applies to most of the Free Software
  46. XFoundation's software and to any other program whose authors commit to
  47. Xusing it.  (Some other Free Software Foundation software is covered by
  48. Xthe GNU Library General Public License instead.)  You can apply it to
  49. Xyour programs, too.
  50. X
  51. X  When we speak of free software, we are referring to freedom, not
  52. Xprice.  Our General Public Licenses are designed to make sure that you
  53. Xhave the freedom to distribute copies of free software (and charge for
  54. Xthis service if you wish), that you receive source code or can get it
  55. Xif you want it, that you can change the software or use pieces of it
  56. Xin new free programs; and that you know you can do these things.
  57. X
  58. X  To protect your rights, we need to make restrictions that forbid
  59. Xanyone to deny you these rights or to ask you to surrender the rights.
  60. XThese restrictions translate to certain responsibilities for you if you
  61. Xdistribute copies of the software, or if you modify it.
  62. X
  63. X  For example, if you distribute copies of such a program, whether
  64. Xgratis or for a fee, you must give the recipients all the rights that
  65. Xyou have.  You must make sure that they, too, receive or can get the
  66. Xsource code.  And you must show them these terms so they know their
  67. Xrights.
  68. X
  69. X  We protect your rights with two steps: (1) copyright the software, and
  70. X(2) offer you this license which gives you legal permission to copy,
  71. Xdistribute and/or modify the software.
  72. X
  73. X  Also, for each author's protection and ours, we want to make certain
  74. Xthat everyone understands that there is no warranty for this free
  75. Xsoftware.  If the software is modified by someone else and passed on, we
  76. Xwant its recipients to know that what they have is not the original, so
  77. Xthat any problems introduced by others will not reflect on the original
  78. Xauthors' reputations.
  79. X
  80. X  Finally, any free program is threatened constantly by software
  81. Xpatents.  We wish to avoid the danger that redistributors of a free
  82. Xprogram will individually obtain patent licenses, in effect making the
  83. Xprogram proprietary.  To prevent this, we have made it clear that any
  84. Xpatent must be licensed for everyone's free use or not licensed at all.
  85. X
  86. X  The precise terms and conditions for copying, distribution and
  87. Xmodification follow.
  88. X
  89. X            GNU GENERAL PUBLIC LICENSE
  90. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  91. X
  92. X  0. This License applies to any program or other work which contains
  93. Xa notice placed by the copyright holder saying it may be distributed
  94. Xunder the terms of this General Public License.  The "Program", below,
  95. Xrefers to any such program or work, and a "work based on the Program"
  96. Xmeans either the Program or any derivative work under copyright law:
  97. Xthat is to say, a work containing the Program or a portion of it,
  98. Xeither verbatim or with modifications and/or translated into another
  99. Xlanguage.  (Hereinafter, translation is included without limitation in
  100. Xthe term "modification".)  Each licensee is addressed as "you".
  101. X
  102. XActivities other than copying, distribution and modification are not
  103. Xcovered by this License; they are outside its scope.  The act of
  104. Xrunning the Program is not restricted, and the output from the Program
  105. Xis covered only if its contents constitute a work based on the
  106. XProgram (independent of having been made by running the Program).
  107. XWhether that is true depends on what the Program does.
  108. X
  109. X  1. You may copy and distribute verbatim copies of the Program's
  110. Xsource code as you receive it, in any medium, provided that you
  111. Xconspicuously and appropriately publish on each copy an appropriate
  112. Xcopyright notice and disclaimer of warranty; keep intact all the
  113. Xnotices that refer to this License and to the absence of any warranty;
  114. Xand give any other recipients of the Program a copy of this License
  115. Xalong with the Program.
  116. X
  117. XYou may charge a fee for the physical act of transferring a copy, and
  118. Xyou may at your option offer warranty protection in exchange for a fee.
  119. X
  120. X  2. You may modify your copy or copies of the Program or any portion
  121. Xof it, thus forming a work based on the Program, and copy and
  122. Xdistribute such modifications or work under the terms of Section 1
  123. Xabove, provided that you also meet all of these conditions:
  124. X
  125. X    a) You must cause the modified files to carry prominent notices
  126. X    stating that you changed the files and the date of any change.
  127. X
  128. X    b) You must cause any work that you distribute or publish, that in
  129. X    whole or in part contains or is derived from the Program or any
  130. X    part thereof, to be licensed as a whole at no charge to all third
  131. X    parties under the terms of this License.
  132. X
  133. X    c) If the modified program normally reads commands interactively
  134. X    when run, you must cause it, when started running for such
  135. X    interactive use in the most ordinary way, to print or display an
  136. X    announcement including an appropriate copyright notice and a
  137. X    notice that there is no warranty (or else, saying that you provide
  138. X    a warranty) and that users may redistribute the program under
  139. X    these conditions, and telling the user how to view a copy of this
  140. X    License.  (Exception: if the Program itself is interactive but
  141. X    does not normally print such an announcement, your work based on
  142. X    the Program is not required to print an announcement.)
  143. X
  144. XThese requirements apply to the modified work as a whole.  If
  145. Xidentifiable sections of that work are not derived from the Program,
  146. Xand can be reasonably considered independent and separate works in
  147. Xthemselves, then this License, and its terms, do not apply to those
  148. Xsections when you distribute them as separate works.  But when you
  149. Xdistribute the same sections as part of a whole which is a work based
  150. Xon the Program, the distribution of the whole must be on the terms of
  151. Xthis License, whose permissions for other licensees extend to the
  152. Xentire whole, and thus to each and every part regardless of who wrote it.
  153. X
  154. XThus, it is not the intent of this section to claim rights or contest
  155. Xyour rights to work written entirely by you; rather, the intent is to
  156. Xexercise the right to control the distribution of derivative or
  157. Xcollective works based on the Program.
  158. X
  159. XIn addition, mere aggregation of another work not based on the Program
  160. Xwith the Program (or with a work based on the Program) on a volume of
  161. Xa storage or distribution medium does not bring the other work under
  162. Xthe scope of this License.
  163. X
  164. X  3. You may copy and distribute the Program (or a work based on it,
  165. Xunder Section 2) in object code or executable form under the terms of
  166. XSections 1 and 2 above provided that you also do one of the following:
  167. X
  168. X    a) Accompany it with the complete corresponding machine-readable
  169. X    source code, which must be distributed under the terms of Sections
  170. X    1 and 2 above on a medium customarily used for software interchange; or,
  171. X
  172. X    b) Accompany it with a written offer, valid for at least three
  173. X    years, to give any third party, for a charge no more than your
  174. X    cost of physically performing source distribution, a complete
  175. X    machine-readable copy of the corresponding source code, to be
  176. X    distributed under the terms of Sections 1 and 2 above on a medium
  177. X    customarily used for software interchange; or,
  178. X
  179. X    c) Accompany it with the information you received as to the offer
  180. X    to distribute corresponding source code.  (This alternative is
  181. X    allowed only for noncommercial distribution and only if you
  182. X    received the program in object code or executable form with such
  183. X    an offer, in accord with Subsection b above.)
  184. X
  185. XThe source code for a work means the preferred form of the work for
  186. Xmaking modifications to it.  For an executable work, complete source
  187. Xcode means all the source code for all modules it contains, plus any
  188. Xassociated interface definition files, plus the scripts used to
  189. Xcontrol compilation and installation of the executable.  However, as a
  190. Xspecial exception, the source code distributed need not include
  191. Xanything that is normally distributed (in either source or binary
  192. Xform) with the major components (compiler, kernel, and so on) of the
  193. Xoperating system on which the executable runs, unless that component
  194. Xitself accompanies the executable.
  195. X
  196. XIf distribution of executable or object code is made by offering
  197. Xaccess to copy from a designated place, then offering equivalent
  198. Xaccess to copy the source code from the same place counts as
  199. Xdistribution of the source code, even though third parties are not
  200. Xcompelled to copy the source along with the object code.
  201. X
  202. X  4. You may not copy, modify, sublicense, or distribute the Program
  203. Xexcept as expressly provided under this License.  Any attempt
  204. Xotherwise to copy, modify, sublicense or distribute the Program is
  205. Xvoid, and will automatically terminate your rights under this License.
  206. XHowever, parties who have received copies, or rights, from you under
  207. Xthis License will not have their licenses terminated so long as such
  208. Xparties remain in full compliance.
  209. X
  210. X  5. You are not required to accept this License, since you have not
  211. Xsigned it.  However, nothing else grants you permission to modify or
  212. Xdistribute the Program or its derivative works.  These actions are
  213. Xprohibited by law if you do not accept this License.  Therefore, by
  214. Xmodifying or distributing the Program (or any work based on the
  215. XProgram), you indicate your acceptance of this License to do so, and
  216. Xall its terms and conditions for copying, distributing or modifying
  217. Xthe Program or works based on it.
  218. X
  219. X  6. Each time you redistribute the Program (or any work based on the
  220. XProgram), the recipient automatically receives a license from the
  221. Xoriginal licensor to copy, distribute or modify the Program subject to
  222. Xthese terms and conditions.  You may not impose any further
  223. Xrestrictions on the recipients' exercise of the rights granted herein.
  224. XYou are not responsible for enforcing compliance by third parties to
  225. Xthis License.
  226. X
  227. X  7. If, as a consequence of a court judgment or allegation of patent
  228. Xinfringement or for any other reason (not limited to patent issues),
  229. Xconditions are imposed on you (whether by court order, agreement or
  230. Xotherwise) that contradict the conditions of this License, they do not
  231. Xexcuse you from the conditions of this License.  If you cannot
  232. Xdistribute so as to satisfy simultaneously your obligations under this
  233. XLicense and any other pertinent obligations, then as a consequence you
  234. Xmay not distribute the Program at all.  For example, if a patent
  235. Xlicense would not permit royalty-free redistribution of the Program by
  236. Xall those who receive copies directly or indirectly through you, then
  237. Xthe only way you could satisfy both it and this License would be to
  238. Xrefrain entirely from distribution of the Program.
  239. X
  240. XIf any portion of this section is held invalid or unenforceable under
  241. Xany particular circumstance, the balance of the section is intended to
  242. Xapply and the section as a whole is intended to apply in other
  243. Xcircumstances.
  244. X
  245. XIt is not the purpose of this section to induce you to infringe any
  246. Xpatents or other property right claims or to contest validity of any
  247. Xsuch claims; this section has the sole purpose of protecting the
  248. Xintegrity of the free software distribution system, which is
  249. Ximplemented by public license practices.  Many people have made
  250. Xgenerous contributions to the wide range of software distributed
  251. Xthrough that system in reliance on consistent application of that
  252. Xsystem; it is up to the author/donor to decide if he or she is willing
  253. Xto distribute software through any other system and a licensee cannot
  254. Ximpose that choice.
  255. X
  256. XThis section is intended to make thoroughly clear what is believed to
  257. Xbe a consequence of the rest of this License.
  258. X
  259. X  8. If the distribution and/or use of the Program is restricted in
  260. Xcertain countries either by patents or by copyrighted interfaces, the
  261. Xoriginal copyright holder who places the Program under this License
  262. Xmay add an explicit geographical distribution limitation excluding
  263. Xthose countries, so that distribution is permitted only in or among
  264. Xcountries not thus excluded.  In such case, this License incorporates
  265. Xthe limitation as if written in the body of this License.
  266. X
  267. X  9. The Free Software Foundation may publish revised and/or new versions
  268. Xof the General Public License from time to time.  Such new versions will
  269. Xbe similar in spirit to the present version, but may differ in detail to
  270. Xaddress new problems or concerns.
  271. X
  272. XEach version is given a distinguishing version number.  If the Program
  273. Xspecifies a version number of this License which applies to it and "any
  274. Xlater version", you have the option of following the terms and conditions
  275. Xeither of that version or of any later version published by the Free
  276. XSoftware Foundation.  If the Program does not specify a version number of
  277. Xthis License, you may choose any version ever published by the Free Software
  278. XFoundation.
  279. X
  280. X  10. If you wish to incorporate parts of the Program into other free
  281. Xprograms whose distribution conditions are different, write to the author
  282. Xto ask for permission.  For software which is copyrighted by the Free
  283. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  284. Xmake exceptions for this.  Our decision will be guided by the two goals
  285. Xof preserving the free status of all derivatives of our free software and
  286. Xof promoting the sharing and reuse of software generally.
  287. X
  288. X                NO WARRANTY
  289. X
  290. X  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  291. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  292. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  293. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  294. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  295. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  296. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  297. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  298. XREPAIR OR CORRECTION.
  299. X
  300. X  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  301. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  302. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  303. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  304. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  305. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  306. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  307. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  308. XPOSSIBILITY OF SUCH DAMAGES.
  309. X
  310. X             END OF TERMS AND CONDITIONS
  311. X
  312. X    Appendix: How to Apply These Terms to Your New Programs
  313. X
  314. X  If you develop a new program, and you want it to be of the greatest
  315. Xpossible use to the public, the best way to achieve this is to make it
  316. Xfree software which everyone can redistribute and change under these terms.
  317. X
  318. X  To do so, attach the following notices to the program.  It is safest
  319. Xto attach them to the start of each source file to most effectively
  320. Xconvey the exclusion of warranty; and each file should have at least
  321. Xthe "copyright" line and a pointer to where the full notice is found.
  322. X
  323. X    <one line to give the program's name and a brief idea of what it does.>
  324. X    Copyright (C) 19yy  <name of author>
  325. X
  326. X    This program is free software; you can redistribute it and/or modify
  327. X    it under the terms of the GNU General Public License as published by
  328. X    the Free Software Foundation; either version 2 of the License, or
  329. X    (at your option) any later version.
  330. X
  331. X    This program is distributed in the hope that it will be useful,
  332. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  333. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  334. X    GNU General Public License for more details.
  335. X
  336. X    You should have received a copy of the GNU General Public License
  337. X    along with this program; if not, write to the Free Software
  338. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  339. X
  340. XAlso add information on how to contact you by electronic and paper mail.
  341. X
  342. XIf the program is interactive, make it output a short notice like this
  343. Xwhen it starts in an interactive mode:
  344. X
  345. X    Gnomovision version 69, Copyright (C) 19yy name of author
  346. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  347. X    This is free software, and you are welcome to redistribute it
  348. X    under certain conditions; type `show c' for details.
  349. X
  350. XThe hypothetical commands `show w' and `show c' should show the appropriate
  351. Xparts of the General Public License.  Of course, the commands you use may
  352. Xbe called something other than `show w' and `show c'; they could even be
  353. Xmouse-clicks or menu items--whatever suits your program.
  354. X
  355. XYou should also get your employer (if you work as a programmer) or your
  356. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  357. Xnecessary.  Here is a sample; alter the names:
  358. X
  359. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  360. X  `Gnomovision' (which makes passes at compilers) written by James Hacker.
  361. X
  362. X  <signature of Ty Coon>, 1 April 1989
  363. X  Ty Coon, President of Vice
  364. X
  365. XThis General Public License does not permit incorporating your program into
  366. Xproprietary programs.  If your program is a subroutine library, you may
  367. Xconsider it more useful to permit linking proprietary applications with the
  368. Xlibrary.  If this is what you want to do, use the GNU Library General
  369. XPublic License instead of this License.
  370. END_OF_FILE
  371.   if test 17982 -ne `wc -c <'COPYING'`; then
  372.     echo shar: \"'COPYING'\" unpacked with wrong size!
  373.   fi
  374.   # end of 'COPYING'
  375. fi
  376. if test -f 'chdir.c' -a "${1}" != "-c" ; then 
  377.   echo shar: Will not clobber existing file \"'chdir.c'\"
  378. else
  379.   echo shar: Extracting \"'chdir.c'\" \(9232 characters\)
  380.   sed "s/^X//" >'chdir.c' <<'END_OF_FILE'
  381. X/*---------------------------------------------------------------------------*
  382. X *
  383. X *                  wish - windowing user friendly shell
  384. X *                 --------------------------------------
  385. X *
  386. X *              (c) Copyright Hellmuth Michaelis 1989 - 1993
  387. X *
  388. X *                  Eggerstedtstr. 28
  389. X *                  22765 Hamburg
  390. X *                  Germany
  391. X *
  392. X *                  Tel:    +49 / 40 / 384298    (private)
  393. X *                  Tel:    +49 / 40 / 55903-170 (at work)
  394. X *                  e-mail: hm@hcshh.hcs.de
  395. X *
  396. X *           All rights are reserved except as explicitly granted
  397. X *                  by written permission of the author.
  398. X *
  399. X *             See the file COPYING, distributed with wish, for
  400. X *                  restriction and warranty information
  401. X *
  402. X *        The wildcard matching routine was written by Rich $alz,
  403. X *     <rsalz@bbn.com> and was released to comp.sources.misc, Volume 17.
  404. X *
  405. X *---------------------------------------------------------------------------*
  406. X *
  407. X *    last edit-date: [Mon Aug 30 12:30:23 1993]
  408. X *
  409. X *    -hm    wildcarding cd
  410. X *    -hm    resolve "~/"
  411. X *
  412. X *----------------------------------------------------------------------------*/
  413. X
  414. X#include "wish.h"        /* local includes */
  415. X
  416. Xstatic char *cd1(char *string);
  417. Xstatic char *wilddir(char *path, char *wildname);
  418. X
  419. X/*---------------------------------------------------------------------------*
  420. X *    change directory, string may contain wildcards
  421. X *----------------------------------------------------------------------------*/
  422. Xint cd(char *string)
  423. X{
  424. X    char *p;
  425. X    
  426. X    if(chdir(string) == 0)        /* try out unresolved first */
  427. X        return(0);
  428. X
  429. X    if((p = cd1(string)) == NULL)    /* try to resolve */
  430. X        return(-1);
  431. X
  432. X    return(chdir(p));        /* try to change dir */
  433. X}
  434. X
  435. X/*---------------------------------------------------------------------------*
  436. X *    return resolved path or NULL if failed 
  437. X *----------------------------------------------------------------------------*/
  438. Xstatic char *cd1(char *string)
  439. X{
  440. X    static char left[MAXPATHLEN+1];        /* contains no wildcards */
  441. X    char wname[MAXPATHLEN+1];        /* current wildname to try */
  442. X
  443. X    register char *sp;            /* ptr into string */
  444. X    register char *lp;            /* ptr into left */    
  445. X    register char *wp;            /* ptr into wname */
  446. X    register char *gp;            /* gp ptr */
  447. X
  448. X    left[0] = wname[0] = '\0';
  449. X    
  450. X    sp = string;
  451. X    lp = left;
  452. X    
  453. X    for(;;)
  454. X    {
  455. X        wp = wname;
  456. X
  457. X        if(*sp == '\0')
  458. X            return(left);
  459. X
  460. X        if((*sp == '~') && (*(sp+1) == '/'))
  461. X        {
  462. X            lp = left;        /* $HOME -> left */
  463. X            gp = envhome;        /* $HOME ptr */
  464. X            while(*gp)        /* copy $HOME -> left */
  465. X                *lp++ = *gp++;    /* new left */
  466. X            *lp++ = '/';        /* terminate left */
  467. X            sp += 2;        /* advance sp */
  468. X            continue;        /* next segment */
  469. X        }
  470. X            
  471. X        while(*sp && (*sp == '/'))    /* check for '/'s */
  472. X            *lp++ = *sp++;
  473. X
  474. X        while(*sp && (*sp != '/'))    /* segment between '/'s -> wname */
  475. X            *wp++ = *sp++;
  476. X        
  477. X        *lp = *wp = '\0';        /* terminate strings */
  478. X
  479. X        if(strpbrk(wname,WILDCHARS)==NULL)    /* check for wildcards */
  480. X        {
  481. X            wp = wname;            /* wname start */
  482. X            while(*wp)            /* cat wname to left */
  483. X                *lp++ = *wp++;
  484. X            continue;            /* next segment */
  485. X        }
  486. X
  487. X        if((gp = wilddir(left, wname)) == NULL)    /* resolve wildcards */
  488. X            return(NULL);            /* not found */
  489. X
  490. X        lp = left;                /* resolved -> left */
  491. X        while(*gp)
  492. X            *lp++ = *gp++;            /* new left */
  493. X        continue;                /* next segment */
  494. X    }
  495. X}
  496. X            
  497. X/*---------------------------------------------------------------------------*
  498. X *    check if "wildname" matches any directory name in directory "path"
  499. X *    return concatenated "path" and matched name from dir "
  500. X *----------------------------------------------------------------------------*/
  501. Xstatic char *wilddir(char *path, char *wildname)
  502. X{
  503. X    register struct direct *dp;        /* dir access */
  504. X    register DIR *dirp;            /* dir access */
  505. X    struct stat fdbuffer;            /* stat buffer */
  506. X    static char wtry[MAXPATHLEN+1];        /* try buffer */
  507. X    char rpath[MAXPATHLEN+1];        /* resulting path */
  508. X    
  509. X    strcpy(rpath, path);            /* path -> result path */
  510. X    strcat(rpath, ".");            /* for readdir */
  511. X    
  512. X    if((dirp = opendir(rpath)) == NULL)
  513. X        return(NULL);            /* cannot open directory */
  514. X
  515. X    for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
  516. X    {
  517. X        if(wildmat(dp->d_name, wildname) == TRUE) /* hit ? */
  518. X        {
  519. X            strcpy(wtry, path);        /* pathname */
  520. X            strcat(wtry, dp->d_name);    /* matchname */
  521. X            if(stat(wtry, &fdbuffer) < 0)
  522. X                continue;        /* not accessible */
  523. X            if(!(S_ISDIR(fdbuffer.st_mode)))/* directory ? */
  524. X                continue;        /* no */
  525. X            closedir(dirp);            /* close */
  526. X            return(wtry);            /* return result */
  527. X        }
  528. X    }
  529. X    closedir(dirp);        /* close */
  530. X    return(NULL);        /* failed */
  531. X}
  532. X
  533. X
  534. X/*  $Revision: 1.4 $
  535. X**
  536. X**  Do shell-style pattern matching for ?, \, [], and * characters.
  537. X**  Might not be robust in face of malformed patterns; e.g., "foo[a-"
  538. X**  could cause a segmentation violation.  It is 8bit clean.
  539. X**
  540. X**  Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.
  541. X**  Rich $alz is now <rsalz@bbn.com>.
  542. X**  April, 1991:  Replaced mutually-recursive calls with in-line code
  543. X**  for the star character.
  544. X**
  545. X**  Special thanks to Lars Mathiesen <thorinn@diku.dk> for the ABORT code.
  546. X**  This can greatly speed up failing wildcard patterns.  For example:
  547. X**    pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-*
  548. X**    text 1:     -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1
  549. X**    text 2:     -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1
  550. X**  Text 1 matches with 51 calls, while text 2 fails with 54 calls.  Without
  551. X**  the ABORT, then it takes 22310 calls to fail.  Ugh.  The following
  552. X**  explanation is from Lars:
  553. X**  The precondition that must be fulfilled is that DoMatch will consume
  554. X**  at least one character in text.  This is true if *p is neither '*' nor
  555. X**  '\0'.)  The last return has ABORT instead of FALSE to avoid quadratic
  556. X**  behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx".  With
  557. X**  FALSE, each star-loop has to run to the end of the text; with ABORT
  558. X**  only the last one does.
  559. X**
  560. X**  Once the control of one instance of DoMatch enters the star-loop, that
  561. X**  instance will return either TRUE or ABORT, and any calling instance
  562. X**  will therefore return immediately after (without calling recursively
  563. X**  again).  In effect, only one star-loop is ever active.  It would be
  564. X**  possible to modify the code to maintain this context explicitly,
  565. X**  eliminating all recursive calls at the cost of some complication and
  566. X**  loss of clarity (and the ABORT stuff seems to be unclear enough by
  567. X**  itself).  I think it would be unwise to try to get this into a
  568. X**  released version unless you have a good test data base to try it out
  569. X**  on.
  570. X*/
  571. X
  572. X    /* What character marks an inverted character class? */
  573. X#define NEGATE_CLASS        '!'    /* -hm , was '^' */
  574. X    /* Is "*" a common pattern? */
  575. X#define OPTIMIZE_JUST_STAR
  576. X    /* Do tar(1) matching rules, which ignore a trailing slash? */
  577. X#undef MATCH_TAR_PATTERN
  578. X
  579. X
  580. X/*
  581. X**  Match text and p, return TRUE, FALSE, or ABORT.
  582. X*/
  583. Xstatic int DoMatch(register char *text, register char *p)
  584. X{
  585. X    register int    dolast;        /* -hm, was "last" */
  586. X    register int    matched;
  587. X    register int    reverse;
  588. X
  589. X    for ( ; *p; text++, p++) {
  590. X    if (*text == '\0' && *p != '*')
  591. X        return ABORT;
  592. X    switch (*p) {
  593. X    case '\\':
  594. X        /* Literal match with following character. */
  595. X        p++;
  596. X        /* FALLTHROUGH */
  597. X    default:
  598. X        if (*text != *p)
  599. X        return FALSE;
  600. X        continue;
  601. X    case '?':
  602. X        /* Match anything. */
  603. X        continue;
  604. X    case '*':
  605. X        while (*++p == '*')
  606. X        /* Consecutive stars act just like one. */
  607. X        continue;
  608. X        if (*p == '\0')
  609. X        /* Trailing star matches everything. */
  610. X        return TRUE;
  611. X        while (*text)
  612. X        if ((matched = DoMatch(text++, p)) != FALSE)
  613. X            return matched;
  614. X        return ABORT;
  615. X    case '[':
  616. X        reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE;
  617. X        if (reverse)
  618. X        /* Inverted character class. */
  619. X        p++;
  620. X        for (dolast = 0400, matched = FALSE; *++p && *p != ']'; dolast = *p)
  621. X        /* This next line requires a good C compiler. */
  622. X        if (*p == '-' ? *text <= *++p && *text >= dolast : *text == *p)
  623. X            matched = TRUE;
  624. X        if (matched == reverse)
  625. X        return FALSE;
  626. X        continue;
  627. X    }
  628. X    }
  629. X
  630. X#ifdef    MATCH_TAR_PATTERN
  631. X    if (*text == '/')
  632. X    return TRUE;
  633. X#endif    /* MATCH_TAR_ATTERN */
  634. X    return *text == '\0';
  635. X}
  636. X
  637. X
  638. X/*
  639. X**  User-level routine.  Returns TRUE or FALSE.
  640. X*/
  641. Xint wildmat(char *text, char *p)
  642. X{
  643. X#ifdef    OPTIMIZE_JUST_STAR
  644. X    if (p[0] == '*' && p[1] == '\0')
  645. X    return TRUE;
  646. X#endif    /* OPTIMIZE_JUST_STAR */
  647. X    return DoMatch(text, p) == TRUE;
  648. X}
  649. X
  650. X
  651. X
  652. X#ifdef    TEST
  653. X#include <stdio.h>
  654. X
  655. X/* Yes, we use gets not fgets.  Sue me. */
  656. Xextern char    *gets();
  657. X
  658. X
  659. Xmain()
  660. X{
  661. X    char     p[80];
  662. X    char     text[80];
  663. X
  664. X    printf("Wildmat tester.  Enter pattern, then strings to test.\n");
  665. X    printf("A blank line gets prompts for a new pattern; a blank pattern\n");
  666. X    printf("exits the program.\n");
  667. X
  668. X    for ( ; ; ) {
  669. X    printf("\nEnter pattern:  ");
  670. X    (void)fflush(stdout);
  671. X    if (gets(p) == NULL || p[0] == '\0')
  672. X        break;
  673. X    for ( ; ; ) {
  674. X        printf("Enter text:  ");
  675. X        (void)fflush(stdout);
  676. X        if (gets(text) == NULL)
  677. X        exit(0);
  678. X        if (text[0] == '\0')
  679. X        /* Blank line; go back and get a new pattern. */
  680. X        break;
  681. X        printf("      %s\n", wildmat(text, p) ? "YES" : "NO");
  682. X    }
  683. X    }
  684. X
  685. X    exit(0);
  686. X    /* NOTREACHED */
  687. X}
  688. X#endif    /* TEST */
  689. X
  690. X/*---------------------------------- EOF -------------------------------------*/
  691. END_OF_FILE
  692.   if test 9232 -ne `wc -c <'chdir.c'`; then
  693.     echo shar: \"'chdir.c'\" unpacked with wrong size!
  694.   fi
  695.   # end of 'chdir.c'
  696. fi
  697. if test -f 'history.c' -a "${1}" != "-c" ; then 
  698.   echo shar: Will not clobber existing file \"'history.c'\"
  699. else
  700.   echo shar: Extracting \"'history.c'\" \(14577 characters\)
  701.   sed "s/^X//" >'history.c' <<'END_OF_FILE'
  702. X/*---------------------------------------------------------------------------*
  703. X *
  704. X *                  wish - windowing user friendly shell
  705. X *                  ------------------------------------
  706. X *
  707. X *               Copyright (c) 1988-1993 Hellmuth Michaelis
  708. X *
  709. X *                  Eggerstedtstr. 28
  710. X *                  22765 Hamburg
  711. X *                  Germany
  712. X *
  713. X *                  Tel:    +49 / 40 / 384298    (private)
  714. X *                  Tel:    +49 / 40 / 55903-170 (at work)
  715. X *                  e-mail: hm@hcshh.hcs.de
  716. X *
  717. X *                          --------oOo--------
  718. X *
  719. X *   This program is free software; you can redistribute it and/or modify
  720. X *   it under the terms of the GNU General Public License as published by
  721. X *   the Free Software Foundation; either version 2 of the License, or
  722. X *   (at your option) any later version.
  723. X *
  724. X *   This program is distributed in the hope that it will be useful,
  725. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  726. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  727. X *   GNU General Public License for more details.
  728. X *
  729. X *   You should have received a copy of the GNU General Public License
  730. X *   along with this program; if not, write to the Free Software
  731. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  732. X *
  733. X *---------------------------------------------------------------------------*
  734. X *
  735. X *    last edit-date: [Wed Sep 22 13:28:09 1993]
  736. X *
  737. X *    -hm    history on commandline
  738. X *    -hm    integrating line handling from terminal.c from my sh
  739. X *    -hm    debugging line editor
  740. X *
  741. X *---------------------------------------------------------------------------*/ 
  742. X
  743. X#include "wish.h"        /* local includes */
  744. X
  745. Xstatic char overstrike;        /* overstrike mode */
  746. Xstatic char kbuf[HISLNLEN];    /* kill buffer */
  747. Xstatic int  kbuf_init = 0;    /* static kill buffer */
  748. Xstatic char *beg;        /* line start      (first char on line)    */
  749. Xstatic char *pnt;        /* next insertion position     (cursor)    */
  750. Xstatic char *end;        /* line end    (first free pos on line)    */
  751. Xstatic char *sbeg;        /* first character on screen        */
  752. Xstatic int lmax;        /* maximum charcount requested from caller */
  753. X
  754. Xstatic void pmstr(char *);        /* forward decl */
  755. Xstatic void pnstr(int, char *);
  756. Xvoid dis_hist(void);
  757. X
  758. X/*---------------------------------------------------------------------------*
  759. X *    return current (cursor) column
  760. X *---------------------------------------------------------------------------*/
  761. Xint curcol(void)
  762. X{
  763. X    return((int)(pnt - sbeg));
  764. X}
  765. X
  766. X/*---------------------------------------------------------------------------*
  767. X *    return true, if commandline empty ( == operate on file window on CR )
  768. X *---------------------------------------------------------------------------*/
  769. Xint cr_on_files(void)
  770. X{
  771. X    return((int)(beg == end));
  772. X}
  773. X
  774. X/*---------------------------------------------------------------------------*
  775. X *    init commandline history system
  776. X *---------------------------------------------------------------------------*/
  777. Xvoid init_history(void)
  778. X{
  779. X    overstrike = 0;        /* insert is default */
  780. X    
  781. X    cur_his = 0;        /* current history pointer */
  782. X    strcpy(cbuff,hislines[cur_his]);
  783. X
  784. X    sbeg = cbuff;        /* screen begin at start of buffer */
  785. X    beg = cbuff + strlen(cbuff);    /* position beg after prompt */
  786. X    pnt = end = beg;    /* point = end = buffer begin */
  787. X
  788. X    kbuf[0] = '\0';        /* init kill - buffer */
  789. X    kbuf_init = 1;        /* static kbuf */
  790. X    
  791. X    lmax = HISLNLEN-1;    /* max line length */
  792. X
  793. X    wmove(cmnd_w,C_LINE,0);    /* beg of line */
  794. X    waddstr(cmnd_w, cbuff);    /* write prompt */
  795. X}    
  796. X
  797. X/*---------------------------------------------------------------------------*
  798. X *    save current commandline to history stack
  799. X *---------------------------------------------------------------------------*/
  800. Xvoid save_line(void)
  801. X{
  802. X    strncpy(hislines[cur_his],cbuff,HISLNLEN-1);
  803. X    if(cur_his == HISLINES-1)
  804. X        cur_his = 0;
  805. X    else
  806. X        cur_his++;
  807. X    hislines[cur_his][3] = '\0';    
  808. X    dis_hist();
  809. X}    
  810. X
  811. X/*---------------------------------------------------------------------------*
  812. X *    get previous history line
  813. X *---------------------------------------------------------------------------*/
  814. Xvoid prev_line(void)
  815. X{
  816. X    if(cur_his == 0)
  817. X        cur_his = HISLINES-1;
  818. X    else
  819. X        cur_his--;
  820. X
  821. X    dis_hist();
  822. X}
  823. X
  824. X/*---------------------------------------------------------------------------*
  825. X *    get next history line
  826. X *---------------------------------------------------------------------------*/
  827. Xvoid next_line(void)
  828. X{
  829. X    if(cur_his == HISLINES-1)
  830. X        cur_his = 0;
  831. X    else
  832. X        cur_his++;
  833. X
  834. X    dis_hist();
  835. X}
  836. X
  837. X/*---------------------------------------------------------------------------*
  838. X *    valid new line from history stack, display it
  839. X *---------------------------------------------------------------------------*/
  840. Xvoid dis_hist(void)
  841. X{
  842. X    strncpy(cbuff,hislines[cur_his],HISLNLEN-1);
  843. X    
  844. X    if((strlen(cbuff)) < COLS)
  845. X    {                 /* new line will fit onto screen */
  846. X        wmove(cmnd_w,C_LINE,0);    /* move to start of line */
  847. X        wclrtoeol(cmnd_w);    /* clear line */
  848. X        wmove(cmnd_w,C_LINE,0);    /* move to start of line */
  849. X        waddstr(cmnd_w, cbuff);    /* write new line */
  850. X        sbeg = cbuff;        /* new screen begin */
  851. X    }
  852. X    else
  853. X    { /* line will not fit onto screen, search end & write new */
  854. X        wmove(cmnd_w,C_LINE,0);        /* start of line */
  855. X        wclrtoeol(cmnd_w);        /* clear to end of line */
  856. X        sbeg = cbuff;            /* start of buffer */
  857. X        while((strlen(sbeg) + 1) > COLS) /* find segment */
  858. X            sbeg += COLS/2;        /*             start */
  859. X        waddstr(cmnd_w, sbeg);        /* write last segment */
  860. X    }
  861. X    pnt = end = (cbuff + strlen(cbuff));
  862. X    beg = cbuff + 3;    /* position beg after prompt */    
  863. X}
  864. X
  865. X/*---------------------------------------------------------------------------*
  866. X *        move cursor forward
  867. X *---------------------------------------------------------------------------*/
  868. Xvoid right_line(void)
  869. X{
  870. X    if(pnt < end)        /* something to move ? */
  871. X    {
  872. X        pnt++;        /* next char */
  873. X        if(pnt > (sbeg + COLS))    /* moving on screen ? */
  874. X        {
  875. X            sbeg += COLS/2;    /* new screen begin */
  876. X            wmove(cmnd_w,C_LINE,0);    /* start of screen */
  877. X            wclrtoeol(cmnd_w);    /* clear line */
  878. X            pmstr(sbeg);        /* write new segment */
  879. X        }
  880. X    }
  881. X}
  882. X
  883. X/*---------------------------------------------------------------------------*
  884. X *        move cursor back one character
  885. X *---------------------------------------------------------------------------*/
  886. Xvoid left_line(void)
  887. X{
  888. X    if(pnt > beg)    /* allowed to move ?? */
  889. X    {
  890. X        pnt--;            /* prev char */
  891. X        if(pnt < sbeg)        /* move on screen ?? */
  892. X        {
  893. X            sbeg -= COLS/2;    /* back 1/2 length */
  894. X            wmove(cmnd_w,C_LINE,0);    /* start of screen */
  895. X            wclrtoeol(cmnd_w);    /* clear line */
  896. X            pmstr(sbeg);        /* print this part of buffer */
  897. X        }
  898. X    }
  899. X}
  900. X
  901. X/*---------------------------------------------------------------------------*
  902. X *    append / insert / overstrike a (printable) character
  903. X *---------------------------------------------------------------------------*/
  904. Xint cmdline(int c)
  905. X{
  906. X    if((end-beg) < lmax)    /* space in buffer ? */
  907. X    {
  908. X        if(pnt == end)    /************ append **********/
  909. X        {
  910. X            *pnt++ = c;        /* store char */
  911. X            end++;            /* new end ptr */
  912. X            *end = '\0';        /* new terminator */
  913. X
  914. X            if((end-sbeg+1) > COLS)
  915. X            {
  916. X                sbeg += COLS/2;
  917. X                wmove(cmnd_w,C_LINE,0);
  918. X                wclrtoeol(cmnd_w);
  919. X                waddstr(cmnd_w, sbeg);
  920. X            }
  921. X            else
  922. X            {
  923. X                waddch(cmnd_w,c);    /* echo char */
  924. X            }
  925. X        }
  926. X        else if(!overstrike)    /************** insert **********/
  927. X        {
  928. X            register char *p;
  929. X            register char *q;
  930. X
  931. X            p = end-1;        /* last char */
  932. X            q = end;        /* last char + 1 */
  933. X            while(q > pnt)        /* shift right buffer */
  934. X                *q-- = *p--;
  935. X
  936. X            *pnt = c;        /* store chr into gap */
  937. X            end++;            /* increment end ptr */
  938. X            *end = '\0';        /* new terminator */
  939. X            
  940. X            if( (pnt+1) > (sbeg + COLS)) /* scroll right ? */
  941. X            {
  942. X                sbeg += COLS/2;    /* new screen beg */
  943. X            }
  944. X            wmove(cmnd_w,C_LINE,0);    /* start of line */
  945. X            pmstr(sbeg);        /* print string */
  946. X            pnt++;            /* new point */
  947. X        }
  948. X        else        /**************    overstrike ****************/
  949. X        {
  950. X            *pnt++ = c;        /* store char */
  951. X
  952. X            if((pnt-sbeg+1) > COLS)
  953. X            {
  954. X                sbeg += COLS/2;
  955. X                wmove(cmnd_w,C_LINE,0);
  956. X                wclrtoeol(cmnd_w);
  957. X                pmstr(sbeg);
  958. X            }
  959. X            else
  960. X            {
  961. X                waddch(cmnd_w,c);    /* echo char */
  962. X            }
  963. X        }
  964. X        return(GOOD);
  965. X    }
  966. X    else
  967. X    {
  968. X        flash();    /* no no .. */
  969. X        return(BAD);    /* don't accept it */
  970. X    }
  971. X}
  972. X
  973. X/*---------------------------------------------------------------------------*
  974. X *        delete character left of cursor
  975. X *---------------------------------------------------------------------------*/
  976. Xvoid handlebs(void)
  977. X{
  978. X    register char *p;
  979. X    register char *q;
  980. X
  981. X    if(pnt == beg)        /* at start of buffer ? */
  982. X        return;        /* yes */
  983. X
  984. X    q = pnt;        /* next char */
  985. X    pnt--;            /* point backward */
  986. X    p = pnt;        /* this char */
  987. X    while(q < end)        /* shift left buffer */
  988. X        *p++ = *q++;
  989. X    end--;            /* new end pointer */
  990. X    *end = '\0';        /* new end terminator */
  991. X
  992. X    if(pnt < sbeg)            /* moved into previous segment ? */
  993. X    {
  994. X        sbeg -= COLS/2;        /* new segment start */
  995. X    }
  996. X    wmove(cmnd_w,C_LINE,0);    /* start of screen line */
  997. X    wclrtoeol(cmnd_w);    /* clear line */
  998. X    pmstr(sbeg);        /* write segment */
  999. X}
  1000. X
  1001. X/*---------------------------------------------------------------------------*
  1002. X *        delete character under cursor
  1003. X *---------------------------------------------------------------------------*/
  1004. Xvoid del_char(void)
  1005. X{
  1006. X    register char *p;
  1007. X    register char *q;
  1008. X
  1009. X    if(pnt == end)        /* at start of buffer ? */
  1010. X        return;        /* yes */
  1011. X
  1012. X    p = pnt;        /* current char */
  1013. X    q = pnt+1;        /* next char */
  1014. X
  1015. X    while(q < end)        /* shift left buffer */
  1016. X        *p++ = *q++;
  1017. X
  1018. X    end--;            /* new end pointer */
  1019. X    *end = '\0';        /* new end terminator */
  1020. X
  1021. X    wmove(cmnd_w,C_LINE,0);    /* start of screen line */
  1022. X    wclrtoeol(cmnd_w);    /* clear line */
  1023. X    pmstr(sbeg);        /* write new segment */
  1024. X}
  1025. X
  1026. X/*---------------------------------------------------------------------------*
  1027. X *        print string, maximum length is COLS
  1028. X *---------------------------------------------------------------------------*/
  1029. Xstatic void pmstr(char *str)
  1030. X{
  1031. X    char buf[256];
  1032. X    register int i = 0;
  1033. X    
  1034. X    while((*str) && (i < COLS))
  1035. X        buf[i++] = *str++;
  1036. X    buf[i] = '\0';
  1037. X    waddstr(cmnd_w, buf);
  1038. X}
  1039. X
  1040. X/*---------------------------------------------------------------------------*
  1041. X *        print string, maximum length parameter <n>
  1042. X *---------------------------------------------------------------------------*/
  1043. Xstatic void pnstr(int n, char *str)
  1044. X{
  1045. X    char buf[256];
  1046. X    register int i = 0;
  1047. X    
  1048. X    while((*str) && (i < n))
  1049. X        buf[i++] = *str++;
  1050. X    buf[i] = '\0';
  1051. X    waddstr(cmnd_w, buf);
  1052. X}
  1053. X
  1054. X/*---------------------------------------------------------------------------*
  1055. X *         delete from cursor to end of line
  1056. X *---------------------------------------------------------------------------*/
  1057. Xvoid clear_toeol(void)
  1058. X{
  1059. X    strcpy(kbuf, pnt);    /* save to kill buffer */
  1060. X    wclrtoeol(cmnd_w);    /* clear line */
  1061. X    end = pnt;        /* new end ptr */
  1062. X    *end = '\0';        /* terminate line */
  1063. X}
  1064. X
  1065. X/*---------------------------------------------------------------------------*
  1066. X *        move cursor to end of line
  1067. X *---------------------------------------------------------------------------*/
  1068. Xvoid eol_line(void)
  1069. X{
  1070. X    if(pnt == end)        /* already at end ? */
  1071. X        return;        /* yes */
  1072. X
  1073. X    if((strlen(cbuff) < COLS) && (sbeg == cbuff))
  1074. X    {
  1075. X        pnt = end;    /* set point to end */
  1076. X    }        
  1077. X    else
  1078. X    {
  1079. X        wmove(cmnd_w,C_LINE,0);    /* start of line */
  1080. X        wclrtoeol(cmnd_w);    /* clear to end of line */
  1081. X        sbeg = cbuff;        /* start of buffer */
  1082. X        while((strlen(sbeg) + 1) > COLS) /* find segment */
  1083. X            sbeg += COLS/2;        /*             start */
  1084. X        waddstr(cmnd_w, sbeg);    /* write last segment */
  1085. X        pnt = end;        /* new point */
  1086. X    }
  1087. X}    
  1088. X
  1089. X/*---------------------------------------------------------------------------*
  1090. X *         move cursor to begin of line
  1091. X *---------------------------------------------------------------------------*/
  1092. Xvoid bol_line(void)
  1093. X{
  1094. X    if(pnt == beg)            /* already at begin of buffer */
  1095. X        return;            /* nothing to do ! */
  1096. X
  1097. X    pnt = beg;            /* point = buffer start */
  1098. X    
  1099. X    if(sbeg != cbuff)        /* not in first screen segment */
  1100. X    {
  1101. X        wmove(cmnd_w,C_LINE,0);    /* cursor -> start of screen */
  1102. X        wclrtoeol(cmnd_w);    /* clear to end of line */
  1103. X        pmstr(cbuff);        /* write from start of buffer */
  1104. X        sbeg = cbuff;        /* screen begin = buffer start */
  1105. X    }
  1106. X}
  1107. X
  1108. X/*---------------------------------------------------------------------------*
  1109. X *        yank text from kill-buffer to current point
  1110. X *---------------------------------------------------------------------------*/
  1111. Xvoid yank(void)
  1112. X{
  1113. X    if(kbuf[0] == '\0')    /* kill buffer empty ? */
  1114. X        return;        /* yes, exit */
  1115. X
  1116. X    if((end - beg) >= lmax)             /* space in buffer ? */
  1117. X    {                     /* no... */
  1118. X        if((overstrike) && (pnt == end)) /* perhaps overstr in the middle ? */
  1119. X            return;             /* no... */
  1120. X        if(!overstrike)             /* insert / append ? */
  1121. X            return;             /* yes */
  1122. X    }
  1123. X
  1124. X    /* here if either space in buffer or overwrite not at end */
  1125. X        
  1126. X    if(pnt == end)        /************ append **********/
  1127. X    {
  1128. X        /* append kill buffer to buffer, observe buffer max length */
  1129. X        
  1130. X        strncat(cbuff, kbuf, lmax);
  1131. X        end = cbuff + strlen(cbuff);
  1132. X        if((end-sbeg+1) > COLS)
  1133. X        {
  1134. X            while((end-sbeg+1) > COLS)
  1135. X                sbeg += COLS/2;
  1136. X            wmove(cmnd_w,C_LINE,0);
  1137. X            wclrtoeol(cmnd_w);
  1138. X            waddstr(cmnd_w, sbeg);    /* write whole new segment */
  1139. X        }
  1140. X        else
  1141. X        {
  1142. X            waddstr(cmnd_w, pnt);    /* write new end */
  1143. X        }
  1144. X        pnt = end;        /* set new pnt */
  1145. X    }
  1146. X    else if(!overstrike)    /************** insert **********/
  1147. X    {
  1148. X        char tail[HISLNLEN];    /* temp storage */
  1149. X        register int i;        /* gp... */
  1150. X        register char *p = pnt;    /* save point pos */
  1151. X        
  1152. X        strcpy(tail, pnt);    /* save string frm point on */
  1153. X        strncpy(pnt, kbuf, lmax); /* insert up to max */
  1154. X        pnt = cbuff + strlen(cbuff);
  1155. X        strcat(pnt, tail);    /* append saved tail */
  1156. X        end = cbuff + strlen(cbuff);
  1157. X
  1158. X        if((pnt-sbeg+1) > COLS)
  1159. X        { /* new point is outside current segment */
  1160. X            while((pnt-sbeg+1) > COLS)
  1161. X                sbeg += COLS/2;
  1162. X            wmove(cmnd_w,C_LINE,0);
  1163. X            wclrtoeol(cmnd_w);
  1164. X            pmstr(sbeg);        /* print string */
  1165. X        }
  1166. X        else
  1167. X        { /* new point is inside current segment */
  1168. X            if((strlen(sbeg)) < COLS) /* line > than screen ? */
  1169. X                i = (sbeg + strlen(sbeg)) - p; /* no */
  1170. X            else
  1171. X                i = (sbeg + COLS) - p; /* yes */
  1172. X            pnstr(i, p);        /* new tail */
  1173. X            p += i;
  1174. X            while(p-- > pnt)
  1175. X                wmove(cmnd_w, C_LINE, (curcol()-1));
  1176. X        }
  1177. X    }
  1178. X    else        /**************    overstrike ****************/
  1179. X    {
  1180. X        register int j = lmax;
  1181. X        register char *k = kbuf;
  1182. X        
  1183. X        while(j-- && *k)
  1184. X            *pnt++ = *k++;    /* copy kbuf over buffer */
  1185. X        
  1186. X        if(pnt > end)    /* buffer grown bigger ? */
  1187. X        {
  1188. X            end = pnt;    /* set new end ptr */
  1189. X            *end = '\0';    /* terminate buffer */
  1190. X        }
  1191. X
  1192. X        if((pnt-sbeg+1) > COLS)
  1193. X        { /* new point is outside current segment */
  1194. X            while((pnt-sbeg+1) > COLS)
  1195. X                sbeg += COLS/2;
  1196. X            wmove(cmnd_w,C_LINE,0);
  1197. X            wclrtoeol(cmnd_w);
  1198. X            pmstr(sbeg);        /* print string */
  1199. X        }
  1200. X        else
  1201. X        { /* new point is inside current segment */
  1202. X            waddstr(cmnd_w, kbuf);
  1203. X        }
  1204. X    }
  1205. X}
  1206. X
  1207. X/*----------------------- E O F -------------------------------------------*/
  1208. END_OF_FILE
  1209.   if test 14577 -ne `wc -c <'history.c'`; then
  1210.     echo shar: \"'history.c'\" unpacked with wrong size!
  1211.   fi
  1212.   # end of 'history.c'
  1213. fi
  1214. if test -f 'wish.c' -a "${1}" != "-c" ; then 
  1215.   echo shar: Will not clobber existing file \"'wish.c'\"
  1216. else
  1217.   echo shar: Extracting \"'wish.c'\" \(14397 characters\)
  1218.   sed "s/^X//" >'wish.c' <<'END_OF_FILE'
  1219. X/*---------------------------------------------------------------------------*
  1220. X *
  1221. X *                  wish - windowing user friendly shell
  1222. X *                  ------------------------------------
  1223. X *
  1224. X *               Copyright (c) 1988-1993 Hellmuth Michaelis
  1225. X *
  1226. X *                  Eggerstedtstr. 28
  1227. X *                  22765 Hamburg
  1228. X *                  Germany
  1229. X *
  1230. X *                  Tel:    +49 / 40 / 384298    (private)
  1231. X *                  Tel:    +49 / 40 / 55903-170 (at work)
  1232. X *                  e-mail: hm@hcshh.hcs.de
  1233. X *
  1234. X *                          --------oOo--------
  1235. X *
  1236. X *   This program is free software; you can redistribute it and/or modify
  1237. X *   it under the terms of the GNU General Public License as published by
  1238. X *   the Free Software Foundation; either version 2 of the License, or
  1239. X *   (at your option) any later version.
  1240. X *
  1241. X *   This program is distributed in the hope that it will be useful,
  1242. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1243. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1244. X *   GNU General Public License for more details.
  1245. X *
  1246. X *   You should have received a copy of the GNU General Public License
  1247. X *   along with this program; if not, write to the Free Software
  1248. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1249. X *
  1250. X *---------------------------------------------------------------------------*
  1251. X *
  1252. X *    Last Edit-Date: [Mon Aug 30 19:59:18 1993]
  1253. X *
  1254. X *    -hm    converting to curses and multiwindows
  1255. X *    -hm    general cleanup ....
  1256. X *    -hm    adding a close-current-dir function and fkey
  1257. X *    -hm    adding history to command line
  1258. X *    -hm    default display attribs on
  1259. X *    -hm    changing coomandline control to emacs-commands
  1260. X *    -hm    vt220 support, housekeeping
  1261. X *    -hm    show time in header
  1262. X *    -hm    try to preserve current position after command
  1263. X *    -hm    backspace char from termio struct
  1264. X *    -hm    porting to 386BSD
  1265. X *    -hm    show links flag
  1266. X *    -hm    config file processing "$HOME/.wishrc"
  1267. X *    -hm    add / subtract option processing
  1268. X *    -hm    exit() -> fatal() changed
  1269. X *    -hm    hpterm / config menu
  1270. X *    -hm    fixed delete character bug
  1271. X *    -hm    fkey label structures
  1272. X *    -hm    ESC,ESC filename completition
  1273. X *    -hm    GNU copyleft
  1274. X *
  1275. X *----------------------------------------------------------------------------*/
  1276. X
  1277. X#define MAIN            /* declare variables into this file */
  1278. X
  1279. X#include "wish.h"        /* everything we want */
  1280. X#include "control.h"        /* control-characters */
  1281. X
  1282. X/*---------------------------------------------------------------------------*
  1283. X *    main loop
  1284. X *---------------------------------------------------------------------------*/
  1285. Xint main (int argc, char *argv[])
  1286. X{
  1287. X    char c;            /* just for argument processing */    
  1288. X    int i;            /* gp int */
  1289. X    int kchar;        /* character from keyboard */
  1290. X    int optmode;        /* add (1) or subtract (0) option mode */    
  1291. X    errorflag = 0;        /* no error yet */
  1292. X
  1293. X    /* first - set up defaults from environment */
  1294. X
  1295. X    if((envhome = getenv("HOME")) == NULL)
  1296. X    {
  1297. X        fprintf(stderr, "\n Environment variable \"HOME\" not set!\n");
  1298. X        exit(1);
  1299. X    }
  1300. X
  1301. X    if((envmore = getenv("PAGER")) == NULL)
  1302. X    {
  1303. X        envmore = "more";    /* default pager for file display */
  1304. X    }
  1305. X
  1306. X    if((envedit = getenv("EDITOR")) == NULL)
  1307. X    {
  1308. X        if((envedit = getenv("VISUAL")) == NULL)
  1309. X        {
  1310. X            envedit = "vi";    /* default editor */
  1311. X        }
  1312. X    }
  1313. X
  1314. X    if((term_string = getenv("TERM")) == NULL)
  1315. X    {
  1316. X        fprintf(stderr,"\nwish: environment variable \"TERM\" undefined, cannot run!\n");
  1317. X        exit(1);        
  1318. X    }
  1319. X
  1320. X    /* init local changable string buffers & pointers */
  1321. X    
  1322. X    strcpy(opt_edit, envedit);    /* cp from env to local buffer */
  1323. X    strcpy(opt_more, envmore);    /* cp from env to local buffer */    
  1324. X    strcpy(opt_wild, "*");        /* init wildcard buffer ... */
  1325. X    
  1326. X    /* second - configure ourselves from users .wishrc */
  1327. X
  1328. X    readrc();            /* read $HOME/.wishrc */
  1329. X
  1330. X    /* adjust for misconfigured wildcards */
  1331. X    
  1332. X    if(opt_wild && (strpbrk(opt_wild,WILDCHARS)==NULL))
  1333. X        opt_wildon = 0;
  1334. X
  1335. X    /* third - configure ourselves from command line parms */
  1336. X    
  1337. X    while((--argc > 0) && ( ((*++argv)[0] == '-') || ((*argv)[0] == '+')) )
  1338. X    {
  1339. X        if((*argv)[0] == '-')
  1340. X            optmode = 0;
  1341. X        else
  1342. X            optmode = 1;
  1343. X
  1344. X        c = *++argv[0];
  1345. X
  1346. X        while(c)
  1347. X        {
  1348. X            switch(c)
  1349. X            {
  1350. X                case 'a':    /* attributes line */
  1351. X                    if(optmode)
  1352. X                        opt_attrib = 1;
  1353. X                    else
  1354. X                        opt_attrib = 0;
  1355. X                    break;
  1356. X                    
  1357. X                case 'd':    /* initial preserve dir when cd .. */
  1358. X                    if(optmode)
  1359. X                        opt_preserve = 1;
  1360. X                    else
  1361. X                        opt_preserve = 0;
  1362. X                    break;
  1363. X                    
  1364. X                case 'f':    /* NO f-key labels on non-hp terminals */
  1365. X                    if(optmode)
  1366. X                        opt_labels = 1;
  1367. X                    else
  1368. X                        opt_labels = 0;
  1369. X                    break;
  1370. X
  1371. X                case 'l':    /* show links not files */
  1372. X                    if(optmode)
  1373. X                        opt_links = 1;
  1374. X                    else
  1375. X                        opt_links = 0;
  1376. X                    break;
  1377. X
  1378. X                case 'p':    /* display current dir in file window  */
  1379. X                    if(optmode)
  1380. X                        opt_point = 1;
  1381. X                    else
  1382. X                        opt_point = 0;
  1383. X                    break;
  1384. X
  1385. X                case 'r':    /* press return to continue */
  1386. X                    if(optmode)
  1387. X                        opt_return = 1;
  1388. X                    else
  1389. X                        opt_return = 0;
  1390. X                    break;
  1391. X
  1392. X                case 'w':    /* enable wildcards */
  1393. X                    if(optmode)
  1394. X                        opt_wildon = 1;
  1395. X                    else
  1396. X                        opt_wildon = 0;
  1397. X                    break;
  1398. X
  1399. X                case 'c':    /* cdrom mode */
  1400. X                    if(optmode)
  1401. X                        opt_cdrom = 1;
  1402. X                    else
  1403. X                        opt_cdrom = 0;
  1404. X                    break;
  1405. X
  1406. X                case 'C':    /* cdrom progs->files */
  1407. X                    if(optmode)
  1408. X                        opt_cdnoprog = 1;
  1409. X                    else
  1410. X                        opt_cdnoprog = 0;
  1411. X                    break;
  1412. X
  1413. X                case 'n':    /* display dot-filenames */
  1414. X                    if(optmode)
  1415. X                        opt_dotnames = 1;
  1416. X                    else
  1417. X                        opt_dotnames = 0;
  1418. X                    break;
  1419. X
  1420. X                default:
  1421. X                    fprintf(stderr,"\nwish: illegal option -%c",c);
  1422. X                    
  1423. X                case '?':
  1424. X                    usage();    /* no return */
  1425. X            }
  1426. X        }
  1427. X    }
  1428. X
  1429. X    if(opt_attrib == 0)        /* if no attrib line, */
  1430. X        opt_links = 0;        /* no link detection necessary */
  1431. X    
  1432. X    /* allocate memory for history */
  1433. X
  1434. X    for(i=0; i < HISLINES; i++)
  1435. X    {
  1436. X        if((hislines[i] = (char *)malloc(HISLNLEN)) == NULL)
  1437. X        {
  1438. X            fprintf(stderr,"\nwish: history malloc failed, exit ...\n");
  1439. X            exit(1);
  1440. X        }
  1441. X        sprintf(hislines[i],"%02d>",i);        /* write prompt */
  1442. X    }
  1443. X
  1444. X    cur_fktab = &sys_keys;        /* current fkey label table */
  1445. X    
  1446. X    init_header();            /* initialize header string */
  1447. X    init_time();            /* display time init */
  1448. X    init_screen();            /* initialize screen */
  1449. X    init_flabels();            /* init fkey-labels */
  1450. X    init_history();            /* init commandline history */
  1451. X    init_files(PRES_NO, NULL);    /* read current directory */
  1452. X    attribs(1);            /* display attributes */
  1453. X    update_all();            /* force first screen-update */
  1454. X
  1455. X    switch(termtype)        /* hpux curses workaround */
  1456. X    {                /* for 2nd bug .....      */
  1457. X        case TERM_VT1:        /* force header update on */
  1458. X        case TERM_VT2:        /* dec terminals 2 times  */
  1459. X        case TERM_VT3:        /* to display inverse!!!! */
  1460. X        case TERM_PCVT:
  1461. X            wmove(cmnd_w, C_HEAD, 0);
  1462. X            waddstr(cmnd_w,headerline);
  1463. X            wrefresh(cmnd_w);
  1464. X            header();
  1465. X            break;
  1466. X    }
  1467. X    
  1468. X    wmove(cmnd_w, C_LINE, curcol());/* cursor to command window */
  1469. X    wrefresh(cmnd_w);        /* update command window */
  1470. X
  1471. X    bschar = erasechar();        /* get backspace char */
  1472. X    
  1473. X    for(;;)
  1474. X    {
  1475. X        kchar = getch();    /* get char */
  1476. X        
  1477. X        clrerror();        /* if error line in header, clear ! */
  1478. X
  1479. X        if(((kchar >= 0x20) && (kchar <= 0x7e)) ||
  1480. X           ((kchar >= 0x80) && (kchar <= 0xff)))
  1481. X        {
  1482. X            /* printable char's to commandline */
  1483. X        
  1484. X            cmdline(kchar);
  1485. X            wmove(cmnd_w, C_LINE, curcol());            
  1486. X            wrefresh(cmnd_w);    
  1487. X            continue;
  1488. X        }
  1489. X        else if(kchar == bschar)    /* backspace */
  1490. X        {
  1491. X            handlebs();
  1492. X        }
  1493. X        else            /* special keys = special actions */
  1494. X        {
  1495. X            switch(kchar)
  1496. X            {
  1497. X                case CR:
  1498. X                    handlecr();
  1499. X                    update_files();
  1500. X                    break;
  1501. X                    
  1502. X                case KEY_DC:    /* delete last char */
  1503. X                    del_char();
  1504. X                    break;
  1505. X
  1506. X                case KEY_BACKSPACE:
  1507. X                    handlebs();
  1508. X                    break;
  1509. X                    
  1510. X                case KEY_RIGHT:    /* right move cursor */
  1511. X                case TAB:
  1512. X                    move_right();
  1513. X                    update_files();
  1514. X                    break;
  1515. X
  1516. X                case KEY_LEFT:    /* left move cursor */
  1517. X                case KEY_BTAB:
  1518. X                    move_left();
  1519. X                    update_files();
  1520. X                    break;
  1521. X
  1522. X                case KEY_UP:    /* up-move cursor */
  1523. X                    move_up();
  1524. X                    update_files();
  1525. X                    break;
  1526. X
  1527. X                case KEY_DOWN:    /* down-move cursor */
  1528. X                    move_down();
  1529. X                    update_files();
  1530. X                    break;
  1531. X
  1532. X                case KEY_HOME:    /* move cursor to first dir */
  1533. X                    move_home();
  1534. X                    update_files();
  1535. X                    break;
  1536. X
  1537. X                case KEY_LL:    /* move cursor to last file */
  1538. X                    move_hmdn();
  1539. X                    update_files();
  1540. X                    break;
  1541. X
  1542. X                case KEY_NPAGE:    /* next/previous page */
  1543. X                    next_page();
  1544. X                    update_files();
  1545. X                    break;
  1546. X                    
  1547. X                case KEY_PPAGE:    /* next/previous page */
  1548. X                    prev_page();
  1549. X                    update_files();
  1550. X                    break;
  1551. X
  1552. X                case KEY_F(1):    /* function key 1 */
  1553. X                    edit_current();
  1554. X                    break;
  1555. X
  1556. X                case KEY_F(2):    /* function key 2 */
  1557. X                    name_echo();
  1558. X                    break;
  1559. X                
  1560. X                case KEY_F(3):    /* function key 3 */
  1561. X                    help();
  1562. X                    update_files();
  1563. X                    break;
  1564. X                    
  1565. X                case KEY_F(4):    /* function key 4 */
  1566. X                    config();
  1567. X                    break;
  1568. X                    
  1569. X                case KEY_F(5):    /* function key 5 */
  1570. X                    tag_current(cur_file);
  1571. X                    move_right();
  1572. X                    update_files();
  1573. X                    break;
  1574. X
  1575. X                case KEY_F(6):    /* function key 6 */
  1576. X                    untag_all();
  1577. X                    update_files();
  1578. X                    break;
  1579. X                    
  1580. X                case KEY_F(7):    /* function key 7 */
  1581. X                    break;
  1582. X                    
  1583. X                case KEY_F(8):    /* function key 8 */
  1584. X                    close_cdir();
  1585. X                    update_files();
  1586. X                    break;
  1587. X
  1588. X                case CNTRL_F:    /* right move cursor */
  1589. X                    right_line();
  1590. X                    break;
  1591. X
  1592. X                case CNTRL_B:    /* left move cursor */
  1593. X                    left_line();
  1594. X                    break;
  1595. X
  1596. X                case CNTRL_P:    /* up-move cursor */
  1597. X                    prev_line();
  1598. X                    break;
  1599. X
  1600. X                case CNTRL_N:    /* down-move cursor */
  1601. X                    next_line();
  1602. X                    break;
  1603. X                    
  1604. X                case CNTRL_D:
  1605. X                    if(cr_on_files())
  1606. X                    {
  1607. X                        move(LINES,COLS-1);    /* last display position */
  1608. X                        free_list();        /* free memory */
  1609. X                        fini_flabels();        /* normal fkey-labels */
  1610. X                        endwin();        /* normalize screen */
  1611. X                        putchar('\n');        /* newline */
  1612. X                        exit(0);
  1613. X                    }
  1614. X                    del_char();
  1615. X                    break;
  1616. X                    
  1617. X                case CNTRL_K:    /* clear to eol */
  1618. X                    clear_toeol();
  1619. X                    break;
  1620. X
  1621. X                case CNTRL_Y:    /* yank kill buffer */
  1622. X                    yank();
  1623. X                    break;
  1624. X
  1625. X                case CNTRL_A:    /* begin of line */
  1626. X                    bol_line();
  1627. X                    break;
  1628. X
  1629. X                case CNTRL_E:    /* end of line */
  1630. X                    eol_line();
  1631. X                    break;
  1632. X                    
  1633. X                case CNTRL_L:    /* refresh */
  1634. X                    touchwin(curscr);
  1635. X                    wrefresh(curscr);
  1636. X                    break;
  1637. X
  1638. X                case ESC:
  1639. X                    kchar = getch();    /* get char */
  1640. X                    switch(kchar)
  1641. X                    {
  1642. X                        case '1':    /* function key 1 */
  1643. X                            edit_current();
  1644. X                            break;
  1645. X        
  1646. X                        case '2':    /* function key 2 */
  1647. X                            name_echo();
  1648. X                            break;
  1649. X                        
  1650. X                        case '3':    /* function key 3 */
  1651. X                            help();
  1652. X                            update_files();
  1653. X                            break;
  1654. X                            
  1655. X                        case '4':    /* function key 4 */
  1656. X                            config();
  1657. X                            break;
  1658. X                            
  1659. X                        case '5':    /* function key 5 */
  1660. X                            tag_current(cur_file);
  1661. X                            move_right();
  1662. X                            update_files();
  1663. X                            break;
  1664. X        
  1665. X                        case '6':    /* function key 6 */
  1666. X                            untag_all();
  1667. X                            update_files();
  1668. X                            break;
  1669. X                            
  1670. X                        case '7':    /* function key 7 */
  1671. X                            break;
  1672. X                            
  1673. X                        case '8':    /* function key 8 */
  1674. X                            close_cdir();
  1675. X                            update_files();
  1676. X                            break;
  1677. X
  1678. X                        case 'n':
  1679. X                        case 'N':
  1680. X                            next_page();
  1681. X                            update_files();
  1682. X                            break;
  1683. X
  1684. X                        case 'p':
  1685. X                        case 'P':
  1686. X                            prev_page();
  1687. X                            update_files();
  1688. X                            break;
  1689. X
  1690. X                        case ESC:    /* filename completition */
  1691. X                            complete();
  1692. X                            break;
  1693. X                    }
  1694. X            }
  1695. X        }
  1696. X        wmove(cmnd_w, C_LINE, curcol());
  1697. X        wrefresh(cmnd_w);
  1698. X    }
  1699. X}
  1700. X
  1701. X/*---------------------------------------------------------------------------*
  1702. X *    initialize curses and window dimensions
  1703. X *---------------------------------------------------------------------------*/
  1704. Xvoid init_screen(void)            /* initialize everything */
  1705. X{
  1706. X    int attrpos;
  1707. X    
  1708. X    initscr();            /* curses init */
  1709. X    nonl();                /* optimize */
  1710. X    raw();                /* raw input */
  1711. X    noecho();            /* do not echo input */
  1712. X    idlok(stdscr,TRUE);        /* use insert/delete */
  1713. X    keypad(stdscr,TRUE);        /* use special keys */
  1714. X    meta(stdscr,TRUE);        /* use 8-bit chars */
  1715. X
  1716. X    set_termtype();            /* init terminal dep. stuff */
  1717. X    
  1718. X    if((cmnd_w = newwin(C_HEIGHT, COLS, 0, 0)) == NULL)
  1719. X        fatal("cannot create command window");
  1720. X
  1721. X    fileheight = LINES-C_HEIGHT;
  1722. X
  1723. X    if(opt_labels)
  1724. X    {
  1725. X        if((flbl_w = newwin(1, COLS, LINES-1, 0)) == NULL)
  1726. X            fatal("cannot create fkey-label window");
  1727. X        fileheight--;
  1728. X    }
  1729. X
  1730. X    if(opt_attrib)
  1731. X    {
  1732. X        fileheight -= 2;
  1733. X        attrpos = C_HEIGHT+fileheight;
  1734. X        
  1735. X        if((attr_w = newwin(2, COLS, attrpos, 0)) == NULL)
  1736. X            fatal("cannot create attribute window");
  1737. X    }
  1738. X
  1739. X    if((fst_w = newwin(2, COLS, C_HEIGHT, 0)) == NULL)
  1740. X        fatal("cannot create file status window");
  1741. X
  1742. X    fileheight -= 2;
  1743. X    
  1744. X    if((file_w = newwin(fileheight, COLS, C_HEIGHT+2, 0)) == NULL)
  1745. X        fatal("cannot create file window");
  1746. X
  1747. X    header();        /* print headerline */
  1748. X    clearok(curscr,TRUE);
  1749. X}    
  1750. X
  1751. X/*---------------------------------------------------------------------------*
  1752. X *    refresh all windows
  1753. X *---------------------------------------------------------------------------*/
  1754. Xvoid update_all(void)
  1755. X{
  1756. X    wnoutrefresh(cmnd_w);
  1757. X    wnoutrefresh(fst_w);
  1758. X    touchwin(file_w);    /* after cur_blink() */
  1759. X    wnoutrefresh(file_w);
  1760. X    if(opt_attrib)
  1761. X        wnoutrefresh(attr_w);
  1762. X    if(opt_labels)
  1763. X        wnoutrefresh(flbl_w);
  1764. X    doupdate();
  1765. X}    
  1766. X
  1767. X/*---------------------------------------------------------------------------*
  1768. X *    refresh file window and attrib window
  1769. X *---------------------------------------------------------------------------*/
  1770. Xvoid update_files(void)
  1771. X{
  1772. X    wnoutrefresh(file_w);
  1773. X    if(opt_attrib)
  1774. X        wnoutrefresh(attr_w);
  1775. X    if(opt_labels)
  1776. X        wnoutrefresh(flbl_w);
  1777. X    doupdate();
  1778. X}    
  1779. X
  1780. X/*---------------------------------------------------------------------------*
  1781. X *    find out terminal-type and initialize terminal specific things
  1782. X *---------------------------------------------------------------------------*/
  1783. Xvoid set_termtype(void)
  1784. X{
  1785. X    static char initvt[] = { ESC, ')', '0', '\0'};
  1786. X
  1787. X    if(ceol_standout_glitch)        /* HP-Terminal */
  1788. X    {
  1789. X        opt_labels = 0;            /* no virtual fkey-labels */
  1790. X        if(!strcmp(term_string,"hpterm")) /* X11 hpterm */
  1791. X            termtype = TERM_HPX;
  1792. X        else
  1793. X            termtype = TERM_HP;
  1794. X    }
  1795. X
  1796. X    else if(!strncmp(term_string,"vt1",3))    /* DEC VT1xx ?? */
  1797. X    {
  1798. X        opt_labels = 1;            /* virtual fkey-labels */
  1799. X        termtype = TERM_VT1;
  1800. X    }
  1801. X
  1802. X    else if(!strncmp(term_string,"vt220",5))/* DEC VT220 ?? */
  1803. X    {
  1804. X        opt_labels = 1;            /* virtual fkey-labels */
  1805. X        write(2, initvt, 3);
  1806. X        termtype = TERM_VT2;
  1807. X    }
  1808. X
  1809. X    else if(!strncmp(term_string,"vt320",5))/* DEC VT320 ?? */
  1810. X    {
  1811. X        opt_labels = 1;            /* virtual fkey-labels */
  1812. X        write(2, initvt, 3);
  1813. X        termtype = TERM_VT3;
  1814. X    }
  1815. X
  1816. X    else if(!strncmp(term_string,"pcvt",4))    /* 386BSD pcvt ?? */
  1817. X    {
  1818. X        opt_labels = 0;            /* real fkey-labels */
  1819. X        write(2, initvt, 3);
  1820. X        termtype = TERM_PCVT;
  1821. X    }
  1822. X
  1823. X    else                    /* dumb thing .. */
  1824. X    {
  1825. X        termtype = TERM_DUMB;
  1826. X    }
  1827. X}
  1828. X
  1829. X/*---------------------------------- EOF ----------------------------------*/
  1830. END_OF_FILE
  1831.   if test 14397 -ne `wc -c <'wish.c'`; then
  1832.     echo shar: \"'wish.c'\" unpacked with wrong size!
  1833.   fi
  1834.   # end of 'wish.c'
  1835. fi
  1836. echo shar: End of archive 2 \(of 4\).
  1837. cp /dev/null ark2isdone
  1838. MISSING=""
  1839. for I in 1 2 3 4 ; do
  1840.     if test ! -f ark${I}isdone ; then
  1841.     MISSING="${MISSING} ${I}"
  1842.     fi
  1843. done
  1844. if test "${MISSING}" = "" ; then
  1845.     echo You have unpacked all 4 archives.
  1846.     rm -f ark[1-9]isdone
  1847. else
  1848.     echo You still must unpack the following archives:
  1849.     echo "        " ${MISSING}
  1850. fi
  1851. exit 0
  1852. exit 0 # Just in case...
  1853.