home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / cwish / part02 < prev    next >
Encoding:
Text File  |  1993-11-01  |  60.3 KB  |  1,948 lines

  1. Newsgroups: comp.sources.misc
  2. From: hm@hcshh.hcs.de (Hellmuth Michaelis)
  3. Subject: v40i069:  cwish - Window Shell / Filemanager v2.00, Part02/05
  4. Message-ID: <1993Nov1.220559.9190@sparky.sterling.com>
  5. X-Md4-Signature: c791e8799db54373a63978b3f4d4d818
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Mon, 1 Nov 1993 22:05:59 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: hm@hcshh.hcs.de (Hellmuth Michaelis)
  12. Posting-number: Volume 40, Issue 69
  13. Archive-name: cwish/part02
  14. Environment: UNIX, ANSI-C, SYSV-CURSES
  15. Supersedes: cwish: Volume 39, Issue 97-100
  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 cwish.c paging.c
  22. # Wrapped by kent@sparky on Fri Oct 29 14:39:10 1993
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 2 (of 5)."'
  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'\" \(9235 characters\)
  380.   sed "s/^X//" >'chdir.c' <<'END_OF_FILE'
  381. X/*---------------------------------------------------------------------------*
  382. X *
  383. X *                  cwish - 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 cwish, 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: [Sun Oct 17 18:03:15 1993]
  408. X *
  409. X *    -hm    wildcarding cd
  410. X *    -hm    resolve "~/"
  411. X *
  412. X *----------------------------------------------------------------------------*/
  413. X
  414. X#include "cwish.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 9235 -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 'cwish.c' -a "${1}" != "-c" ; then 
  698.   echo shar: Will not clobber existing file \"'cwish.c'\"
  699. else
  700.   echo shar: Extracting \"'cwish.c'\" \(15027 characters\)
  701.   sed "s/^X//" >'cwish.c' <<'END_OF_FILE'
  702. X/*---------------------------------------------------------------------------*
  703. X *
  704. X *                  cwish - 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: [Fri Oct 29 13:14:20 1993]
  736. X *
  737. X *    -hm    converting to curses and multiwindows
  738. X *    -hm    general cleanup ....
  739. X *    -hm    adding a close-current-dir function and fkey
  740. X *    -hm    adding history to command line
  741. X *    -hm    default display attribs on
  742. X *    -hm    changing coomandline control to emacs-commands
  743. X *    -hm    vt220 support, housekeeping
  744. X *    -hm    show time in header
  745. X *    -hm    try to preserve current position after command
  746. X *    -hm    backspace char from termio struct
  747. X *    -hm    porting to 386BSD
  748. X *    -hm    show links flag
  749. X *    -hm    config file processing "$HOME/.wishrc"
  750. X *    -hm    add / subtract option processing
  751. X *    -hm    exit() -> fatal() changed
  752. X *    -hm    hpterm / config menu
  753. X *    -hm    fixed delete character bug
  754. X *    -hm    fkey label structures
  755. X *    -hm    ESC,ESC filename completition
  756. X *    -hm    GNU copyleft
  757. X *    -go    ported to Ultrix
  758. X *    -hm    move after tag
  759. X *    -hm    alternate attribs line
  760. X *    -hm    rename everything to cwish ...
  761. X *
  762. X *----------------------------------------------------------------------------*/
  763. X
  764. X#define MAIN            /* declare variables into this file */
  765. X
  766. X#include "cwish.h"        /* everything we want */
  767. X#include "control.h"        /* control-characters */
  768. X
  769. X/*---------------------------------------------------------------------------*
  770. X *    main loop
  771. X *---------------------------------------------------------------------------*/
  772. Xint main (int argc, char *argv[])
  773. X{
  774. X    char c;            /* just for argument processing */    
  775. X    int i;            /* gp int */
  776. X    int kchar;        /* character from keyboard */
  777. X    int optmode;        /* add (1) or subtract (0) option mode */    
  778. X    errorflag = 0;        /* no error yet */
  779. X
  780. X    /* first - set up defaults from environment */
  781. X
  782. X    if((envhome = getenv("HOME")) == NULL)
  783. X    {
  784. X        fprintf(stderr, "\n Environment variable \"HOME\" not set!\n");
  785. X        exit(1);
  786. X    }
  787. X
  788. X    if((envmore = getenv("PAGER")) == NULL)
  789. X    {
  790. X        envmore = "more";    /* default pager for file display */
  791. X    }
  792. X
  793. X    if((envedit = getenv("EDITOR")) == NULL)
  794. X    {
  795. X        if((envedit = getenv("VISUAL")) == NULL)
  796. X        {
  797. X            envedit = "vi";    /* default editor */
  798. X        }
  799. X    }
  800. X
  801. X    if((term_string = getenv("TERM")) == NULL)
  802. X    {
  803. X        fprintf(stderr,"\ncwish: environment variable \"TERM\" undefined, cannot run!\n");
  804. X        exit(1);        
  805. X    }
  806. X
  807. X    /* init local changable string buffers & pointers */
  808. X    
  809. X    strcpy(opt_edit, envedit);    /* cp from env to local buffer */
  810. X    strcpy(opt_more, envmore);    /* cp from env to local buffer */    
  811. X    strcpy(opt_wild, "*");        /* init wildcard buffer ... */
  812. X    
  813. X    /* second - configure ourselves from users .cwishrc */
  814. X
  815. X    readrc();            /* read $HOME/.cwishrc */
  816. X
  817. X    /* adjust for misconfigured wildcards */
  818. X    
  819. X    if(opt_wild && (strpbrk(opt_wild,WILDCHARS)==NULL))
  820. X        opt_wildon = 0;
  821. X
  822. X    /* third - configure ourselves from command line parms */
  823. X    
  824. X    while((--argc > 0) && ( ((*++argv)[0] == '-') || ((*argv)[0] == '+')) )
  825. X    {
  826. X        if((*argv)[0] == '-')
  827. X            optmode = 0;
  828. X        else
  829. X            optmode = 1;
  830. X
  831. X        c = *++argv[0];
  832. X
  833. X        while(c)
  834. X        {
  835. X            switch(c)
  836. X            {
  837. X                case 'a':    /* attributes line */
  838. X                    if(optmode)
  839. X                        opt_attrib = 1;
  840. X                    else
  841. X                        opt_attrib = 0;
  842. X                    break;
  843. X                    
  844. X                case 'd':    /* initial preserve dir when cd .. */
  845. X                    if(optmode)
  846. X                        opt_preserve = 1;
  847. X                    else
  848. X                        opt_preserve = 0;
  849. X                    break;
  850. X                    
  851. X                case 'f':    /* NO f-key labels on non-hp terminals */
  852. X                    if(optmode)
  853. X                        opt_labels = 1;
  854. X                    else
  855. X                        opt_labels = 0;
  856. X                    break;
  857. X
  858. X                case 'l':    /* show links not files */
  859. X                    if(optmode)
  860. X                        opt_links = 1;
  861. X                    else
  862. X                        opt_links = 0;
  863. X                    break;
  864. X
  865. X                case 'p':    /* display current dir in file window  */
  866. X                    if(optmode)
  867. X                        opt_point = 1;
  868. X                    else
  869. X                        opt_point = 0;
  870. X                    break;
  871. X
  872. X                case 'r':    /* press return to continue */
  873. X                    if(optmode)
  874. X                        opt_return = 1;
  875. X                    else
  876. X                        opt_return = 0;
  877. X                    break;
  878. X
  879. X                case 'w':    /* enable wildcards */
  880. X                    if(optmode)
  881. X                        opt_wildon = 1;
  882. X                    else
  883. X                        opt_wildon = 0;
  884. X                    break;
  885. X
  886. X                case 'c':    /* cdrom mode */
  887. X                    if(optmode)
  888. X                        opt_cdrom = 1;
  889. X                    else
  890. X                        opt_cdrom = 0;
  891. X                    break;
  892. X
  893. X                case 'C':    /* cdrom progs->files */
  894. X                    if(optmode)
  895. X                        opt_cdnoprog = 1;
  896. X                    else
  897. X                        opt_cdnoprog = 0;
  898. X                    break;
  899. X
  900. X                case 'n':    /* display dot-filenames */
  901. X                    if(optmode)
  902. X                        opt_dotnames = 1;
  903. X                    else
  904. X                        opt_dotnames = 0;
  905. X                    break;
  906. X
  907. X                default:
  908. X                    fprintf(stderr,"\ncwish: illegal option -%c",c);
  909. X                    
  910. X                case '?':
  911. X                    usage();    /* no return */
  912. X            }
  913. X        }
  914. X    }
  915. X
  916. X    if(opt_attrib == 0)        /* if no attrib line, */
  917. X        opt_links = 0;        /* no link detection necessary */
  918. X    
  919. X    /* allocate memory for history */
  920. X
  921. X    for(i=0; i < HISLINES; i++)
  922. X    {
  923. X        if((hislines[i] = (char *)malloc(HISLNLEN)) == NULL)
  924. X        {
  925. X            fprintf(stderr,"\ncwish: history malloc failed, exit ...\n");
  926. X            exit(1);
  927. X        }
  928. X        sprintf(hislines[i],"%02d>",i);        /* write prompt */
  929. X    }
  930. X
  931. X    cur_fktab = &sys_keys;        /* current fkey label table */
  932. X    
  933. X    init_header();            /* initialize header string */
  934. X    init_time();            /* display time init */
  935. X    init_screen();            /* initialize screen */
  936. X    init_flabels();            /* init fkey-labels */
  937. X    init_history();            /* init commandline history */
  938. X    init_files(PRES_NO, NULL);    /* read current directory */
  939. X    attribs(1);            /* display attributes */
  940. X    update_all();            /* force first screen-update */
  941. X
  942. X    switch(termtype)        /* hpux curses workaround */
  943. X    {                /* for 2nd bug .....      */
  944. X        case TERM_VT1:        /* force header update on */
  945. X        case TERM_VT2:        /* dec terminals 2 times  */
  946. X        case TERM_VT3:        /* to display inverse!!!! */
  947. X        case TERM_PCVT:
  948. X            wmove(cmnd_w, C_HEAD, 0);
  949. X            waddstr(cmnd_w,headerline);
  950. X            wrefresh(cmnd_w);
  951. X            header();
  952. X            break;
  953. X    }
  954. X    
  955. X    wmove(cmnd_w, C_LINE, curcol());/* cursor to command window */
  956. X    wrefresh(cmnd_w);        /* update command window */
  957. X
  958. X    bschar = erasechar();        /* get backspace char */
  959. X    
  960. X    for(;;)
  961. X    {
  962. X        kchar = getch();    /* get char */
  963. X        
  964. X        clrerror();        /* if error line in header, clear ! */
  965. X
  966. X        if(((kchar >= 0x20) && (kchar <= 0x7e)) ||
  967. X           ((kchar >= 0x80) && (kchar <= 0xff)))
  968. X        {
  969. X            /* printable char's to commandline */
  970. X        
  971. X            cmdline(kchar);
  972. X            wmove(cmnd_w, C_LINE, curcol());            
  973. X            wrefresh(cmnd_w);    
  974. X            continue;
  975. X        }
  976. X        else if(kchar == bschar)    /* backspace */
  977. X        {
  978. X            handlebs();
  979. X        }
  980. X        else            /* special keys = special actions */
  981. X        {
  982. X            switch(kchar)
  983. X            {
  984. X                case CR:
  985. X                case LF:
  986. X#ifdef KEY_ENTER
  987. X                case KEY_ENTER:
  988. X#endif
  989. X                    handlecr();
  990. X                    update_files();
  991. X                    break;
  992. X                    
  993. X                case KEY_DC:    /* delete last char */
  994. X                    del_char();
  995. X                    break;
  996. X
  997. X                case KEY_BACKSPACE:
  998. X                    handlebs();
  999. X                    break;
  1000. X                    
  1001. X                case KEY_RIGHT:    /* right move cursor */
  1002. X                case TAB:
  1003. X                    move_right();
  1004. X                    update_files();
  1005. X                    break;
  1006. X
  1007. X                case KEY_LEFT:    /* left move cursor */
  1008. X#ifdef KEY_BTAB
  1009. X                case KEY_BTAB:
  1010. X#endif
  1011. X                    move_left();
  1012. X                    update_files();
  1013. X                    break;
  1014. X
  1015. X                case KEY_UP:    /* up-move cursor */
  1016. X                    move_up();
  1017. X                    update_files();
  1018. X                    break;
  1019. X
  1020. X                case KEY_DOWN:    /* down-move cursor */
  1021. X                    move_down();
  1022. X                    update_files();
  1023. X                    break;
  1024. X
  1025. X                case KEY_HOME:    /* move cursor to first dir */
  1026. X                    move_home();
  1027. X                    update_files();
  1028. X                    break;
  1029. X
  1030. X                case KEY_LL:    /* move cursor to last file */
  1031. X                    move_hmdn();
  1032. X                    update_files();
  1033. X                    break;
  1034. X
  1035. X                case KEY_NPAGE:    /* next/previous page */
  1036. X                    next_page();
  1037. X                    update_files();
  1038. X                    break;
  1039. X                    
  1040. X                case KEY_PPAGE:    /* next/previous page */
  1041. X                    prev_page();
  1042. X                    update_files();
  1043. X                    break;
  1044. X
  1045. X                case KEY_F(1):    /* function key 1 */
  1046. X                    edit_current();
  1047. X                    break;
  1048. X
  1049. X                case KEY_F(2):    /* function key 2 */
  1050. X                    name_echo();
  1051. X                    break;
  1052. X                
  1053. X                case KEY_F(3):    /* function key 3 */
  1054. X                    help();
  1055. X                    update_files();
  1056. X                    break;
  1057. X                    
  1058. X                case KEY_F(4):    /* function key 4 */
  1059. X                    config();
  1060. X                    break;
  1061. X                    
  1062. X                case KEY_F(5):    /* function key 5 */
  1063. X                    tag_current(cur_file);
  1064. X                    if(opt_tagmove)
  1065. X                        move_right();
  1066. X                    wnoutrefresh(fst_w);
  1067. X                    update_files();
  1068. X                    break;
  1069. X
  1070. X                case KEY_F(6):    /* function key 6 */
  1071. X                    untag_all();
  1072. X                    wnoutrefresh(fst_w);
  1073. X                    update_files();
  1074. X                    break;
  1075. X                    
  1076. X                case KEY_F(7):    /* function key 7 */
  1077. X                    if(opt_attrib)
  1078. X                    {
  1079. X                        opt_altattr = ~opt_altattr;
  1080. X                        attribs(1);
  1081. X                        wnoutrefresh(attr_w);
  1082. X                        doupdate();
  1083. X                    }
  1084. X                    break;
  1085. X                    
  1086. X                case KEY_F(8):    /* function key 8 */
  1087. X                    close_cdir();
  1088. X                    update_files();
  1089. X                    break;
  1090. X
  1091. X                case CNTRL_F:    /* right move cursor */
  1092. X                    right_line();
  1093. X                    break;
  1094. X
  1095. X                case CNTRL_B:    /* left move cursor */
  1096. X                    left_line();
  1097. X                    break;
  1098. X
  1099. X                case CNTRL_P:    /* up-move cursor */
  1100. X                    prev_line();
  1101. X                    break;
  1102. X
  1103. X                case CNTRL_N:    /* down-move cursor */
  1104. X                    next_line();
  1105. X                    break;
  1106. X                    
  1107. X                case CNTRL_D:
  1108. X                    if(cr_on_files())
  1109. X                    {
  1110. X                        move(LINES,COLS-1);    /* last display position */
  1111. X                        free_list();        /* free memory */
  1112. X                        fini_flabels();        /* normal fkey-labels */
  1113. X                        endwin();        /* normalize screen */
  1114. X                        putchar('\n');        /* newline */
  1115. X                        exit(0);
  1116. X                    }
  1117. X                    del_char();
  1118. X                    break;
  1119. X                    
  1120. X                case CNTRL_K:    /* clear to eol */
  1121. X                    clear_toeol();
  1122. X                    break;
  1123. X
  1124. X                case CNTRL_Y:    /* yank kill buffer */
  1125. X                    yank();
  1126. X                    break;
  1127. X
  1128. X                case CNTRL_A:    /* begin of line */
  1129. X                    bol_line();
  1130. X                    break;
  1131. X
  1132. X                case CNTRL_E:    /* end of line */
  1133. X                    eol_line();
  1134. X                    break;
  1135. X                    
  1136. X                case CNTRL_L:    /* refresh */
  1137. X                    touchwin(curscr);
  1138. X                    wrefresh(curscr);
  1139. X                    break;
  1140. X
  1141. X                case ESC:
  1142. X                    kchar = getch();    /* get char */
  1143. X                    switch(kchar)
  1144. X                    {
  1145. X                        case '1':    /* function key 1 */
  1146. X                            edit_current();
  1147. X                            break;
  1148. X        
  1149. X                        case '2':    /* function key 2 */
  1150. X                            name_echo();
  1151. X                            break;
  1152. X                        
  1153. X                        case '3':    /* function key 3 */
  1154. X                            help();
  1155. X                            update_files();
  1156. X                            break;
  1157. X                            
  1158. X                        case '4':    /* function key 4 */
  1159. X                            config();
  1160. X                            break;
  1161. X                            
  1162. X                        case '5':    /* function key 5 */
  1163. X                            tag_current(cur_file);
  1164. X                            if(opt_tagmove)
  1165. X                                move_right();
  1166. X                            wnoutrefresh(fst_w);
  1167. X                            update_files();
  1168. X                            break;
  1169. X
  1170. X                        case '6':    /* function key 6 */
  1171. X                            untag_all();
  1172. X                            wnoutrefresh(fst_w);
  1173. X                            update_files();
  1174. X                            break;
  1175. X                    
  1176. X                        case '7':    /* function key 7 */
  1177. X                            if(opt_attrib)
  1178. X                            {
  1179. X                                opt_altattr = ~opt_altattr;
  1180. X                                attribs(1);
  1181. X                                wnoutrefresh(attr_w);
  1182. X                                doupdate();
  1183. X                            }
  1184. X                            break;
  1185. X                            
  1186. X                        case '8':    /* function key 8 */
  1187. X                            close_cdir();
  1188. X                            update_files();
  1189. X                            break;
  1190. X
  1191. X                        case 'n':
  1192. X                        case 'N':
  1193. X                            next_page();
  1194. X                            update_files();
  1195. X                            break;
  1196. X
  1197. X                        case 'p':
  1198. X                        case 'P':
  1199. X                            prev_page();
  1200. X                            update_files();
  1201. X                            break;
  1202. X
  1203. X                        case ESC:    /* filename completition */
  1204. X                            complete();
  1205. X                            break;
  1206. X                    }
  1207. X            }
  1208. X        }
  1209. X        wmove(cmnd_w, C_LINE, curcol());
  1210. X        wrefresh(cmnd_w);
  1211. X    }
  1212. X}
  1213. X
  1214. X/*---------------------------------------------------------------------------*
  1215. X *    initialize curses and window dimensions
  1216. X *---------------------------------------------------------------------------*/
  1217. Xvoid init_screen(void)            /* initialize everything */
  1218. X{
  1219. X    int attrpos;
  1220. X    
  1221. X    initscr();            /* curses init */
  1222. X    nonl();                /* optimize */
  1223. X    raw();                /* raw input */
  1224. X    noecho();            /* do not echo input */
  1225. X    idlok(stdscr,TRUE);        /* use insert/delete */
  1226. X    keypad(stdscr,TRUE);        /* use special keys */
  1227. X    meta(stdscr,TRUE);        /* use 8-bit chars */
  1228. X
  1229. X    set_termtype();            /* init terminal dep. stuff */
  1230. X    
  1231. X    if((cmnd_w = newwin(C_HEIGHT, COLS, 0, 0)) == NULL)
  1232. X        fatal("cannot create command window");
  1233. X
  1234. X    fileheight = LINES-C_HEIGHT;
  1235. X
  1236. X    if(opt_labels)
  1237. X    {
  1238. X        if((flbl_w = newwin(1, COLS, LINES-1, 0)) == NULL)
  1239. X            fatal("cannot create fkey-label window");
  1240. X        fileheight--;
  1241. X    }
  1242. X
  1243. X    if(opt_attrib)
  1244. X    {
  1245. X        fileheight -= 2;
  1246. X        attrpos = C_HEIGHT+fileheight;
  1247. X        
  1248. X        if((attr_w = newwin(2, COLS, attrpos, 0)) == NULL)
  1249. X            fatal("cannot create attribute window");
  1250. X    }
  1251. X
  1252. X    if((fst_w = newwin(2, COLS, C_HEIGHT, 0)) == NULL)
  1253. X        fatal("cannot create file status window");
  1254. X
  1255. X    fileheight -= 2;
  1256. X    
  1257. X    if((file_w = newwin(fileheight, COLS, C_HEIGHT+2, 0)) == NULL)
  1258. X        fatal("cannot create file window");
  1259. X
  1260. X    header();        /* print headerline */
  1261. X    clearok(curscr,TRUE);
  1262. X}    
  1263. X
  1264. X/*---------------------------------------------------------------------------*
  1265. X *    refresh all windows
  1266. X *---------------------------------------------------------------------------*/
  1267. Xvoid update_all(void)
  1268. X{
  1269. X    wnoutrefresh(cmnd_w);
  1270. X    wnoutrefresh(fst_w);
  1271. X    touchwin(file_w);    /* after cur_blink() */
  1272. X    wnoutrefresh(file_w);
  1273. X    if(opt_attrib)
  1274. X        wnoutrefresh(attr_w);
  1275. X    if(opt_labels)
  1276. X        wnoutrefresh(flbl_w);
  1277. X    doupdate();
  1278. X}    
  1279. X
  1280. X/*---------------------------------------------------------------------------*
  1281. X *    refresh file window and attrib window
  1282. X *---------------------------------------------------------------------------*/
  1283. Xvoid update_files(void)
  1284. X{
  1285. X    wnoutrefresh(file_w);
  1286. X    if(opt_attrib)
  1287. X        wnoutrefresh(attr_w);
  1288. X    if(opt_labels)
  1289. X        wnoutrefresh(flbl_w);
  1290. X    doupdate();
  1291. X}    
  1292. X
  1293. X/*---------------------------------------------------------------------------*
  1294. X *    find out terminal-type and initialize terminal specific things
  1295. X *---------------------------------------------------------------------------*/
  1296. Xvoid set_termtype(void)
  1297. X{
  1298. X    static char initvt[] = { ESC, ')', '0', '\0'};
  1299. X
  1300. X    if(ceol_standout_glitch)        /* HP-Terminal */
  1301. X    {
  1302. X        opt_labels = 0;            /* no virtual fkey-labels */
  1303. X        if(!strcmp(term_string,"hpterm")) /* X11 hpterm */
  1304. X            termtype = TERM_HPX;
  1305. X        else
  1306. X            termtype = TERM_HP;
  1307. X    }
  1308. X
  1309. X    else if(!strncmp(term_string,"vt1",3))    /* DEC VT1xx ?? */
  1310. X    {
  1311. X        opt_labels = 1;            /* virtual fkey-labels */
  1312. X        termtype = TERM_VT1;
  1313. X    }
  1314. X
  1315. X    else if(!strncmp(term_string,"vt220",5))/* DEC VT220 ?? */
  1316. X    {
  1317. X        opt_labels = 1;            /* virtual fkey-labels */
  1318. X        write(2, initvt, 3);
  1319. X        termtype = TERM_VT2;
  1320. X    }
  1321. X
  1322. X    else if(!strncmp(term_string,"vt320",5))/* DEC VT320 ?? */
  1323. X    {
  1324. X        opt_labels = 1;            /* virtual fkey-labels */
  1325. X        write(2, initvt, 3);
  1326. X        termtype = TERM_VT3;
  1327. X    }
  1328. X
  1329. X    else if(!strncmp(term_string,"pcvt",4))    /* 386BSD pcvt ?? */
  1330. X    {
  1331. X        opt_labels = 0;            /* real fkey-labels */
  1332. X        write(2, initvt, 3);
  1333. X        termtype = TERM_PCVT;
  1334. X    }
  1335. X
  1336. X    else                    /* dumb thing .. */
  1337. X    {
  1338. X        termtype = TERM_DUMB;
  1339. X    }
  1340. X}
  1341. X
  1342. X/*---------------------------------- EOF ----------------------------------*/
  1343. END_OF_FILE
  1344.   if test 15027 -ne `wc -c <'cwish.c'`; then
  1345.     echo shar: \"'cwish.c'\" unpacked with wrong size!
  1346.   fi
  1347.   # end of 'cwish.c'
  1348. fi
  1349. if test -f 'paging.c' -a "${1}" != "-c" ; then 
  1350.   echo shar: Will not clobber existing file \"'paging.c'\"
  1351. else
  1352.   echo shar: Extracting \"'paging.c'\" \(14712 characters\)
  1353.   sed "s/^X//" >'paging.c' <<'END_OF_FILE'
  1354. X/*---------------------------------------------------------------------------*
  1355. X *
  1356. X *                  cwish - windowing user friendly shell
  1357. X *                  -------------------------------------
  1358. X *
  1359. X *               Copyright (c) 1988-1993 Hellmuth Michaelis
  1360. X *
  1361. X *                  Eggerstedtstr. 28
  1362. X *                  22765 Hamburg
  1363. X *                  Germany
  1364. X *
  1365. X *                  Tel:    +49 / 40 / 384298    (private)
  1366. X *                  Tel:    +49 / 40 / 55903-170 (at work)
  1367. X *                  e-mail: hm@hcshh.hcs.de
  1368. X *
  1369. X *                          --------oOo--------
  1370. X *
  1371. X *   This program is free software; you can redistribute it and/or modify
  1372. X *   it under the terms of the GNU General Public License as published by
  1373. X *   the Free Software Foundation; either version 2 of the License, or
  1374. X *   (at your option) any later version.
  1375. X *
  1376. X *   This program is distributed in the hope that it will be useful,
  1377. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1378. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1379. X *   GNU General Public License for more details.
  1380. X *
  1381. X *   You should have received a copy of the GNU General Public License
  1382. X *   along with this program; if not, write to the Free Software
  1383. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1384. X *
  1385. X *---------------------------------------------------------------------------*
  1386. X *
  1387. X *    Last Edit-Date: [Wed Oct 20 11:17:34 1993]
  1388. X *
  1389. X *    -hm    conversion to curses
  1390. X *    -hm    multiple windows
  1391. X *    -hm    debugging paging routines
  1392. X *    -hm    hpux 9.0 zero pointers ...
  1393. X *    -hm    housekeeping
  1394. X *
  1395. X *----------------------------------------------------------------------------*/
  1396. X
  1397. X#include "cwish.h"
  1398. X
  1399. Xstatic char curpath[MAXPATHLEN+1];    /* current path buffer normalized for screen */
  1400. Xstatic int lastpage;            /* number of last page */
  1401. X
  1402. Xstatic void make_cpath();        /* get & format current directory */
  1403. Xstatic void dis_cpath(int init);    /* print current directory & entries */
  1404. Xstatic void new_stops();
  1405. Xstatic void dis_init(struct onefile *);
  1406. Xstatic void dis_play(struct onefile *);
  1407. Xstatic void show_blip(void);
  1408. X
  1409. X/*---------------------------------------------------------------------------*
  1410. X *    get & format current directory for display
  1411. X *---------------------------------------------------------------------------*/
  1412. Xstatic void make_cpath(void)
  1413. X{
  1414. X    int i,j,width;
  1415. X    
  1416. X    if((getcwd(curpath, MAXPATHLEN)) == NULL)
  1417. X    {
  1418. X        error("internal getwcd() error, chdir to HOME");
  1419. X        if((chdir(envhome)) == -1)
  1420. X            fatal("cannot chdir() to HOME");
  1421. X        if((getcwd(curpath, MAXPATHLEN)) == NULL)
  1422. X            fatal("twotimes internal getcwd() error");
  1423. X    }
  1424. X
  1425. X    strcpy(cur_path,curpath);    /* for program execution */
  1426. X    
  1427. X    width = COLS-CURDIRW-(ENTRYSW+ENTRYCW);
  1428. X    i = strlen(curpath);
  1429. X    if(i > width)
  1430. X    {
  1431. X        j = 0;
  1432. X        i = i - width + 4;
  1433. X        while(curpath[i++] != '/')
  1434. X            ;
  1435. X        curpath[j++] = '.';
  1436. X        curpath[j++] = '.';
  1437. X        curpath[j++] = '.';
  1438. X        curpath[j++] = ' ';
  1439. X        i--;
  1440. X        while(curpath[i])
  1441. X            curpath[j++] = curpath[i++];
  1442. X        curpath[j++] = '\0';
  1443. X    }
  1444. X}                
  1445. X
  1446. X/*---------------------------------------------------------------------------*
  1447. X *    print current directory & entries
  1448. X *---------------------------------------------------------------------------*/
  1449. Xstatic void dis_cpath(int init)
  1450. X{
  1451. X    static int p_init = 1;
  1452. X    int i;
  1453. X    
  1454. X    if(p_init || init)
  1455. X    {
  1456. X        wmove(fst_w, 0, 0);        /* move to dir string */
  1457. X        wattron(fst_w, A_UNDERLINE);    /* underline on */
  1458. X        waddstr(fst_w, "Directory:");    /* description */
  1459. X        wattroff(fst_w, A_UNDERLINE);    /* end underline */
  1460. X    }
  1461. X    wmove(fst_w, 0, CURDIRW);
  1462. X    waddstr(fst_w, curpath);        /* print current path */
  1463. X
  1464. X    i = CURDIRW + strlen(curpath);
  1465. X    
  1466. X    while(i++ < COLS-ENTRYSW-ENTRYCW)
  1467. X        waddch(fst_w, SPACE);
  1468. X
  1469. X    if(p_init || init)
  1470. X    {
  1471. X        wmove(fst_w, 0, COLS-ENTRYSW-ENTRYCW); /* move to entries string */
  1472. X        wclrtoeol(fst_w);
  1473. X        wattron(fst_w, A_UNDERLINE);    /* underline on */
  1474. X
  1475. X        if(tagsize)    /* tagged files, display sum of sizes */
  1476. X        {
  1477. X            waddstr(fst_w, "Byte:");    /* description */
  1478. X            wmove(fst_w, 0, COLS-ENTRYCW-4);/* move to entries string */
  1479. X            wattroff(fst_w, A_UNDERLINE);    /* underline off */
  1480. X            wprintw(fst_w, "%8d", tagsize);    /* print size */
  1481. X        }
  1482. X        else if(opt_wildon)    /* wildcarding enabled */
  1483. X        {
  1484. X            waddstr(fst_w, "Matches:");    /* description */
  1485. X            wmove(fst_w, 0, COLS-ENTRYCW);    /* move to entries string */
  1486. X            wattroff(fst_w, A_UNDERLINE);    /* underline off */
  1487. X            waddstr(fst_w, counter);    /* print current path */
  1488. X        }
  1489. X        else            /* normal operation */
  1490. X        {
  1491. X            waddstr(fst_w, "Entries:");    /* description */
  1492. X            wmove(fst_w, 0, COLS-ENTRYCW);    /* move to entries string */
  1493. X            wattroff(fst_w, A_UNDERLINE);    /* underline off */
  1494. X            waddstr(fst_w, counter);    /* print current path */
  1495. X        }
  1496. X        p_init = 0;
  1497. X    }
  1498. X}
  1499. X
  1500. X/*---------------------------------------------------------------------------*
  1501. X *    calculate new "tab" stops for filename display
  1502. X *---------------------------------------------------------------------------*/
  1503. Xstatic void new_stops(void)
  1504. X{
  1505. X    int j = STARTCOL;        /* start value */
  1506. X    int maxcol = 0;            /* global no of cols */
  1507. X    
  1508. X    while(maxcol < STOPS)
  1509. X    {
  1510. X        stops[maxcol++] = j;    /* set stop point */
  1511. X        j += MINSPACE;        /* add minimum space count between names */
  1512. X        j += maxfnleng;        /* and next filename's length */
  1513. X        if((j + MINSPACE + maxfnleng) > COLS)
  1514. X        {
  1515. X            stops[maxcol] = 0;    /* end marker */
  1516. X            break;            /* leave loop */
  1517. X        }
  1518. X    }
  1519. X}    
  1520. X
  1521. X/*---------------------------------------------------------------------------*
  1522. X *    display next file page (if any) in file window
  1523. X *---------------------------------------------------------------------------*/
  1524. Xvoid next_page(void)
  1525. X{
  1526. X    if(cur_page >= lastpage)    /* already on last page ? */
  1527. X        return;            /* yes, leave .. */
  1528. X        
  1529. X    wclear(file_w);            /* clear current window */
  1530. X    dis_cpath(0);            /* current path & entries */
  1531. X
  1532. X    for(;;)
  1533. X    {
  1534. X        if((cur_file->page & PAGE_MSK) == ((cur_page+1) & PAGE_MSK))
  1535. X            break;
  1536. X        if(cur_file->next != NULL)
  1537. X            cur_file = cur_file->next;    /* next entry */
  1538. X        else
  1539. X            break;
  1540. X    }
  1541. X
  1542. X    cur_page = cur_file->page & PAGE_MSK;
  1543. X    
  1544. X    scr_beg = cur_file;
  1545. X    scr_end = cur_file;
  1546. X
  1547. X    dis_play(cur_file);        /* display directories */
  1548. X    show_blip();
  1549. X    cur_inv(cur_file);
  1550. X}
  1551. X
  1552. X/*---------------------------------------------------------------------------*
  1553. X *    display previous file page (if any) in file window
  1554. X *---------------------------------------------------------------------------*/
  1555. Xvoid prev_page(void)
  1556. X{
  1557. X    if(cur_page <= 0)        /* is there a previous page ? */
  1558. X        return;            /* no, return */
  1559. X
  1560. X    wclear(file_w);            /* clear current window */
  1561. X    dis_cpath(0);            /* display current path & entries */
  1562. X    
  1563. X    cur_file = first;
  1564. X
  1565. X    for(;;)    
  1566. X    {
  1567. X        if((cur_file->page & PAGE_MSK) == ((cur_page-1) & PAGE_MSK))
  1568. X            break;
  1569. X        if(cur_file->next != NULL)
  1570. X            cur_file = cur_file->next;    /* next entry */
  1571. X        else
  1572. X            break;
  1573. X    }
  1574. X
  1575. X    cur_page = cur_file->page & PAGE_MSK;
  1576. X    
  1577. X    scr_beg = cur_file;
  1578. X    scr_end = cur_file;
  1579. X    
  1580. X    dis_play(cur_file);        /* display directories */
  1581. X    show_blip();
  1582. X    cur_inv(cur_file);
  1583. X}
  1584. X
  1585. X/*---------------------------------------------------------------------------*
  1586. X *    re-fill/refresh file window with data for current dir
  1587. X *---------------------------------------------------------------------------*/
  1588. Xvoid fresh_files(void) 
  1589. X{
  1590. X    scr_end = scr_beg;        /* init */
  1591. X    wclear(file_w);            /* clear current window */
  1592. X    dis_cpath(1);            /* display current path */
  1593. X    dis_play(scr_beg);        /* display directories */
  1594. X    show_blip();            /* show more indicator */
  1595. X    cur_inv(cur_file);        /* highlight old */
  1596. X}
  1597. X
  1598. X/*---------------------------------------------------------------------------*
  1599. X *    initialize the file diaply window
  1600. X *---------------------------------------------------------------------------*/
  1601. Xvoid init_files(int preserve, char *dirname)
  1602. X{
  1603. X    char filename[MAXPATHLEN];
  1604. X    int page;
  1605. X    int row;
  1606. X    int col;
  1607. X
  1608. X    if(cur_file != NULL)
  1609. X    {
  1610. X        cur_blink(cur_file);    /* blink current file while reading */
  1611. X        wrefresh(file_w);    /* update blinking */
  1612. X        page = cur_file->page & PAGE_MSK;
  1613. X        row = cur_file->orow;
  1614. X        col = cur_file->ocol;
  1615. X    }
  1616. X    else
  1617. X    {
  1618. X        page = row = col = 0;
  1619. X    }
  1620. X    
  1621. X    if(preserve == PRES_NORM)
  1622. X    {
  1623. X        strcpy(filename, cur_file->onam);
  1624. X        page = cur_file->page & PAGE_MSK;
  1625. X        row = cur_file->orow;
  1626. X        col = cur_file->ocol;
  1627. X    }
  1628. X    else if(preserve == PRES_DD)
  1629. X    {
  1630. X        if(dirname != NULL && *dirname && opt_preserve)
  1631. X        {
  1632. X            char *ptr;
  1633. X
  1634. X            if((ptr = (char *)rindex(dirname, '/')) == NULL)
  1635. X            {
  1636. X                preserve = PRES_NO;
  1637. X            }
  1638. X            else if(*dirname)
  1639. X            {
  1640. X                ptr++;
  1641. X                strcpy(filename, ptr);
  1642. X                page = 0;
  1643. X                row = 0;
  1644. X                col = 0;
  1645. X            }
  1646. X            else
  1647. X            {
  1648. X                preserve = PRES_NO;
  1649. X            }
  1650. X        }
  1651. X        else
  1652. X        {
  1653. X            preserve = PRES_NO;
  1654. X        }
  1655. X    }
  1656. X    
  1657. X    cur_page = 0;            /* file display page 0 */
  1658. X    make_cpath();            /* format current dir */
  1659. X    
  1660. X    if(fill_list() != 0)        /* get directory data into list */
  1661. X    {
  1662. X        if(first != NULL)    /* if any malloced space ... */
  1663. X            free_list();    /* FREE IT !!! */
  1664. X        return;            /* return with error */
  1665. X    }
  1666. X
  1667. X    dis_cpath(1);            /* display current path */
  1668. X    new_stops();            /* compute new stops-table */
  1669. X    cur_file = first;        /* current file is first */
  1670. X    scr_beg = first;        /* first filename on display */
  1671. X    scr_end = first;        /* last filename on display */
  1672. X    wclear(file_w);            /* clear current window */
  1673. X    
  1674. X    while(cur_file != NULL)        /* init whole list */
  1675. X    {
  1676. X        dis_init(cur_file);    /* page init directories */
  1677. X        cur_page++;        /* next page */
  1678. X        cur_file = scr_end->next;    /* new pointer */
  1679. X        scr_beg = cur_file;    /* new screen start */
  1680. X    }
  1681. X    lastpage = cur_page-1;        /* init last page no. */
  1682. X    cur_page = 0;            /* file display page 0 */
  1683. X    cur_file = first;        /* current file is first */
  1684. X    scr_beg = first;        /* first filename on display */
  1685. X    scr_end = first;        /* last filename on display */
  1686. X
  1687. X    if(preserve == PRES_NORM || preserve == PRES_DD)
  1688. X    {
  1689. X        int found = 0;
  1690. X        int length = strlen(filename);
  1691. X        struct onefile *last_file = cur_file;
  1692. X    
  1693. X        while(!found)
  1694. X        {
  1695. X            if(preserve == PRES_NORM)
  1696. X            {
  1697. X                if(!(strncmp(filename,last_file->onam,length)))
  1698. X                {
  1699. X                    found = 1;
  1700. X                    break;
  1701. X                }
  1702. X            }
  1703. X            else if(preserve == PRES_DD)
  1704. X            {
  1705. X                if(!(strncmp(filename,&(last_file->onam[1]),length)))
  1706. X                {
  1707. X                    found = 1;
  1708. X                    break;
  1709. X                }
  1710. X            }
  1711. X            
  1712. X            if(last_file->next)
  1713. X                last_file = last_file->next;
  1714. X            else
  1715. X                break;
  1716. X        }
  1717. X        if(found)
  1718. X        {
  1719. X            page = ((last_file->page) & PAGE_MSK);
  1720. X            row = last_file->orow;
  1721. X            col = last_file->ocol;
  1722. X        }
  1723. X        if(page > lastpage)
  1724. X            page = lastpage;
  1725. X        
  1726. X        for(;;)
  1727. X        {
  1728. X            if((cur_file->page & PAGE_MSK) == (page & PAGE_MSK))
  1729. X                break;
  1730. X            if(cur_file->next != NULL)
  1731. X                cur_file = cur_file->next;
  1732. X            else    
  1733. X                break;
  1734. X        }
  1735. X        cur_page = cur_file->page & PAGE_MSK;
  1736. X    
  1737. X        scr_beg = cur_file;
  1738. X        scr_end = cur_file;
  1739. X
  1740. X        if(found)
  1741. X            cur_file = last_file;
  1742. X        else
  1743. X        {
  1744. X            last_file = cur_file;
  1745. X
  1746. X            while((last_file->page & PAGE_MSK) == (page & PAGE_MSK))
  1747. X            {
  1748. X                if((last_file->orow == row) && (last_file->ocol == col))
  1749. X                {
  1750. X                    cur_file = last_file;
  1751. X                    break;
  1752. X                }
  1753. X                if(last_file->next != NULL)
  1754. X                    last_file = last_file->next;
  1755. X                else    
  1756. X                    break;
  1757. X            }
  1758. X        }
  1759. X    }
  1760. X    dis_play(scr_beg);        /* display directories */
  1761. X    show_blip();
  1762. X    cur_inv(cur_file);        /* handle current filename */
  1763. X}
  1764. X
  1765. X/*---------------------------------------------------------------------------*
  1766. X *    display file window
  1767. X *---------------------------------------------------------------------------*/
  1768. Xstatic void dis_play(register struct onefile *n_ptr)
  1769. X{
  1770. X    int displaytype = 1;        /* display file type */
  1771. X    int what = n_ptr->onam[0];    /* dirs, files, executables */
  1772. X    int curp = n_ptr->page & PAGE_MSK;
  1773. X
  1774. X    while(n_ptr)
  1775. X    {
  1776. X        if(displaytype)        /* print description */
  1777. X        {
  1778. X            wmove(file_w, n_ptr->orow, 0);    /* move type pos. */
  1779. X            wattron(file_w, A_UNDERLINE);    /* underline */
  1780. X            switch(what)
  1781. X            {
  1782. X                case ISDIR:    /* directories */
  1783. X                    waddstr(file_w, "Dirs:");
  1784. X                    break;
  1785. X                    
  1786. X                case ISPROG:    /* executables */
  1787. X                    waddstr(file_w, "Progs:");
  1788. X                    break;
  1789. X                    
  1790. X                case ISDATA:    /* data */
  1791. X                    waddstr(file_w, "Files:");
  1792. X                    break;
  1793. X                    
  1794. X                case ISCHAR:    /* char devs */
  1795. X                    waddstr(file_w, "Cdevs:");
  1796. X                    break;
  1797. X                    
  1798. X                case ISBLOCK:    /* block devs */
  1799. X                    waddstr(file_w, "Bdevs:");
  1800. X                    break;
  1801. X                    
  1802. X                case ISPIPE:    /* pipes */
  1803. X                    waddstr(file_w, "Pipes:");
  1804. X                    break;
  1805. X                    
  1806. X                case ISSOCK:    /* sockets */
  1807. X                    waddstr(file_w, "Sockt:");
  1808. X                    break;
  1809. X                    
  1810. X                default:    /* data */
  1811. X                    waddstr(file_w, "Unkwn:");
  1812. X                    break;
  1813. X            }
  1814. X            wattroff(file_w, A_UNDERLINE);    /* end underline */
  1815. X            displaytype = 0;          /* reset displaytype */
  1816. X        }
  1817. X
  1818. X        is_tagged(n_ptr);    /* print it */
  1819. X
  1820. X        scr_end = n_ptr;    /* new last screen pos */
  1821. X
  1822. X        if(!n_ptr->next)    /* next entry valid ?? */
  1823. X            break;        /* no, current is last */
  1824. X            
  1825. X        n_ptr = n_ptr->next;    /* next entry */
  1826. X
  1827. X        if(n_ptr->page != curp)    /* if next page != current page ..*/
  1828. X            break;        /* ..exit */
  1829. X
  1830. X        if(n_ptr && (what != n_ptr->onam[0]))    /* new type ?? */
  1831. X        {
  1832. X            what = n_ptr->onam[0];        /* new type */
  1833. X            displaytype = 1;        /* display */
  1834. X        }
  1835. X    }
  1836. X}
  1837. X
  1838. X/*---------------------------------------------------------------------------*
  1839. X *    initialize file window display
  1840. X *---------------------------------------------------------------------------*/
  1841. Xstatic void dis_init(register struct onefile *n_ptr)
  1842. X{
  1843. X    int firstpage = 1;        /* mark first page flag */
  1844. X    int row = 0;            /* current row */
  1845. X    int what = n_ptr->onam[0];    /* dirs, files, executables */
  1846. X    int stop = 0;            /* first stop */
  1847. X    int col = stops[stop];        /* current column */
  1848. X
  1849. X    firstpage = 1;
  1850. X    
  1851. X    while(n_ptr && ( row < fileheight ))    /* while not at end of list */
  1852. X                        /*  and in file window .... */
  1853. X    {
  1854. X        if(firstpage)    /* mark first file first page */
  1855. X        {
  1856. X            n_ptr->page = (cur_page | FIRST);
  1857. X            firstpage = 0;
  1858. X        }
  1859. X        else        
  1860. X        {
  1861. X            n_ptr->page = cur_page;
  1862. X        }
  1863. X        
  1864. X        n_ptr->orow = row;    /* save current pos */
  1865. X        n_ptr->ocol = col;    /*  into list entry */
  1866. X
  1867. X        stop++;            /* next stop */
  1868. X        if(stops[stop] == 0)    /* last stop ? */
  1869. X        {
  1870. X            row++;        /* next row */
  1871. X            stop = 0;    /* new stop */
  1872. X        }
  1873. X        col = stops[stop];    /* new col */
  1874. X
  1875. X        scr_end = n_ptr;    /* new last screen pos */
  1876. X
  1877. X        n_ptr = n_ptr->next;    /* next entry */
  1878. X
  1879. X        if(n_ptr && (what != n_ptr->onam[0]))    /* new type ?? */
  1880. X        {
  1881. X            what = n_ptr->onam[0];    /* new type */
  1882. X
  1883. X            if(stop == 0)        /* compute vertical space */
  1884. X            {
  1885. X                row++;
  1886. X            }
  1887. X            else
  1888. X            {
  1889. X                row += 2;
  1890. X                stop = 0;
  1891. X            }
  1892. X            col = stops[stop];    /* new column */
  1893. X        }
  1894. X    }
  1895. X}
  1896. X
  1897. X/*---------------------------------------------------------------------------*
  1898. X *    show wether we have a previous(^), next(v) or just one(*) page
  1899. X *---------------------------------------------------------------------------*/
  1900. Xstatic void show_blip(void)
  1901. X{
  1902. X    if((!cur_page) && (!lastpage))        /* just one page */
  1903. X        return;
  1904. X        
  1905. X    wmove(file_w, fileheight-1 , COLS-1);
  1906. X
  1907. X    wattrset(file_w, A_REVERSE);
  1908. X    
  1909. X    if((!cur_page) && (lastpage))    /* first page */
  1910. X    {
  1911. X        waddch(file_w,'v');
  1912. X    }
  1913. X    else if(lastpage && (cur_page == lastpage)) /* last page */
  1914. X    {
  1915. X        waddch(file_w,'^');
  1916. X    }
  1917. X    else                    /* somewhere between */
  1918. X    {
  1919. X        waddch(file_w,'*');
  1920. X    }
  1921. X    wattrset(file_w, A_NORMAL);    
  1922. X}
  1923. X
  1924. X/*---------------------------------- EOF -------------------------------------*/
  1925. END_OF_FILE
  1926.   if test 14712 -ne `wc -c <'paging.c'`; then
  1927.     echo shar: \"'paging.c'\" unpacked with wrong size!
  1928.   fi
  1929.   # end of 'paging.c'
  1930. fi
  1931. echo shar: End of archive 2 \(of 5\).
  1932. cp /dev/null ark2isdone
  1933. MISSING=""
  1934. for I in 1 2 3 4 5 ; do
  1935.     if test ! -f ark${I}isdone ; then
  1936.     MISSING="${MISSING} ${I}"
  1937.     fi
  1938. done
  1939. if test "${MISSING}" = "" ; then
  1940.     echo You have unpacked all 5 archives.
  1941.     rm -f ark[1-9]isdone
  1942. else
  1943.     echo You still must unpack the following archives:
  1944.     echo "        " ${MISSING}
  1945. fi
  1946. exit 0
  1947. exit 0 # Just in case...
  1948.