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

  1. Newsgroups: comp.sources.misc
  2. From: hm@hcshh.hcs.de (Hellmuth Michaelis)
  3. Subject: v40i070:  cwish - Window Shell / Filemanager v2.00, Part03/05
  4. Message-ID: <1993Nov1.220630.9299@sparky.sterling.com>
  5. X-Md4-Signature: 0725d0c5793805c6619074257d222948
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Mon, 1 Nov 1993 22:06:30 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: hm@hcshh.hcs.de (Hellmuth Michaelis)
  12. Posting-number: Volume 40, Issue 70
  13. Archive-name: cwish/part03
  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:  config.c cwish.h files.c header.c history.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 3 (of 5)."'
  26. if test -f 'config.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'config.c'\"
  28. else
  29.   echo shar: Extracting \"'config.c'\" \(8738 characters\)
  30.   sed "s/^X//" >'config.c' <<'END_OF_FILE'
  31. X/*---------------------------------------------------------------------------*
  32. X *
  33. X *                  cwish - windowing user friendly shell
  34. X *                  -------------------------------------
  35. X *
  36. X *              (c) Copyright Hellmuth Michaelis 1989 - 1993
  37. X *
  38. X *                  Eggerstedtstr. 28
  39. X *                  22765 Hamburg
  40. X *                  Germany
  41. X *
  42. X *                  Tel:    +49 / 40 / 384298    (private)
  43. X *                  Tel:    +49 / 40 / 55903-170 (at work)
  44. X *                  e-mail: hm@hcshh.hcs.de
  45. X *
  46. X *           All rights are reserved except as explicitly granted
  47. X *                  by written permission of the author.
  48. X *
  49. X *             See the file COPYING, distributed with cwish, for
  50. X *                  restriction and warranty information
  51. X *
  52. X *---------------------------------------------------------------------------*
  53. X *
  54. X *    Last Edit-Date: [Sun Oct 17 18:17:40 1993]
  55. X *
  56. X *    -hm    initial configuration menu design
  57. X *    -hm    altcharset debugging
  58. X *    -hm    fkey labels for config screen
  59. X *    -hm    enter wildcard string
  60. X *    -go    ported to Ultrix
  61. X *
  62. X *----------------------------------------------------------------------------*/
  63. X
  64. X#include "cwish.h"
  65. X#include "config.h"
  66. X#include "control.h"
  67. X
  68. Xextern char *contin;        /* from help.c */
  69. X
  70. Xstatic char *help1 = "Use cursor keys to move to the items you wish change";
  71. Xstatic char *help2 = "SPACE toggles between YES and NO";
  72. Xstatic char *help3 = "CONTROL-D exits configuration menu";
  73. X
  74. Xstatic void separate(int);
  75. Xstatic char *enter_string(int row, int col, char *string, int length);
  76. X
  77. Xstatic char was_wildcard[OPTSLEN+1];
  78. Xstatic char was_wildon;
  79. Xstatic char was_cdrom;
  80. Xstatic char was_cdnoprog;
  81. X
  82. X/*---------------------------------------------------------------------------*
  83. X *    config function key labels
  84. X *---------------------------------------------------------------------------*/
  85. X
  86. Xstatic struct fk_tab conf_keys[] = {
  87. X    {"                ", "         "},
  88. X    {"                ", "         "},
  89. X    {"                ", "         "},
  90. X    {"                ", "         "},
  91. X    {"                ", "         "},
  92. X    {"                ", "         "},
  93. X    {"                ", "         "},
  94. X    {"  Exit   Config ", "         "}
  95. X};
  96. X
  97. X/*---------------------------------------------------------------------------*
  98. X *    run-time configuration menu
  99. X *---------------------------------------------------------------------------*/
  100. Xvoid config(void)
  101. X{
  102. X    struct item *ip;
  103. X    char *q;
  104. X    int c;
  105. X    int i;
  106. X    int dids = 0;
  107. X    int helpline = 0;
  108. X    
  109. X    suspend_time();        /* stop updating time */
  110. X
  111. X    cur_fktab = &conf_keys;    /* config screen fkey label table */
  112. X    init_flabels();
  113. X
  114. X    strcpy(was_wildcard, opt_wild);
  115. X    was_wildon = opt_wildon;
  116. X    was_cdrom = opt_cdrom;
  117. X    was_cdnoprog = opt_cdnoprog;
  118. X    
  119. X    wmove(stdscr, 0, 0);    /* first line */
  120. X    wclear(stdscr);        /* clear window */
  121. X    touchwin(stdscr);    /* touch it */
  122. X    wnoutrefresh(stdscr);    /* force refresh */
  123. X
  124. X    move(0, 0);        /* first line */
  125. X    attron(A_REVERSE);    /* highlight on */
  126. X    addstr(headerline);    /* program/copyright header */
  127. X    attroff(A_REVERSE);    /* highlight off */
  128. X
  129. X    ip = FIRST_I;
  130. X    
  131. X    /* display menu */
  132. X    
  133. X    do
  134. X    {
  135. X        if(!dids && ip->type & ITEM_NOCHANGE)
  136. X        {
  137. X            dids = 1;
  138. X            separate(ip->row - 2);
  139. X        }
  140. X            
  141. X        mvaddstr(ip->row, ip->col, ip->name);
  142. X        standout();
  143. X        switch(ip->type & ~ITEM_NOCHANGE)
  144. X        {
  145. X            case ITEM_ONOFF:
  146. X                if(*(ip->value))
  147. X                    addstr("YES");
  148. X                else
  149. X                    addstr(" NO");
  150. X                break;
  151. X            case ITEM_STRING:
  152. X                if(*((char *)ip->value))
  153. X                    addstr((char *)ip->value);
  154. X                else
  155. X                {
  156. X                    standend();
  157. X                    addstr("[Not set]");
  158. X                }
  159. X                break;
  160. X            case ITEM_CHAR:
  161. X                if((char)*(ip->value))
  162. X                    addch((char)*(ip->value));
  163. X                else
  164. X                {
  165. X                    standend();
  166. X                    addstr("[Not set]");
  167. X                }
  168. X                break;
  169. X        }
  170. X        standend();
  171. X        if(helpline < ip->row)
  172. X            helpline = ip->row;
  173. X    }
  174. X    while((ip = ip->next) != FIRST_I);
  175. X
  176. X    helpline += 3;
  177. X
  178. X    separate(helpline-1);
  179. X    
  180. X    move(helpline + 2, (COLS-strlen(help1))/2);
  181. X    addstr(help1);
  182. X
  183. X    move(helpline + 3, (COLS-strlen(help2))/2);
  184. X    addstr(help2);
  185. X
  186. X    move(helpline + 4, (COLS-strlen(help3))/2);
  187. X    addstr(help3);
  188. X    
  189. X    ip = FIRST_I;
  190. X
  191. X    /* cruise in menu */
  192. X
  193. X    i = 0;
  194. X    
  195. X    for(;;)
  196. X    {
  197. X        move(helpline, 0);
  198. X        clrtoeol();
  199. X        move(helpline, (COLS-strlen(ip->help))/2);
  200. X        addstr(ip->help);
  201. X
  202. X        move(ip->row, ((ip->col)+(ip->nl)));
  203. X        refresh();
  204. X
  205. X        c = getch();
  206. X
  207. X        switch(c)
  208. X        {
  209. X            case CR:
  210. X                if(ip->type != ITEM_STRING)
  211. X                    break;
  212. X
  213. X                if((q = enter_string(ip->row, ((ip->col)+(ip->nl)), (char *)ip->value , OPTSLEN)) != NULL)
  214. X                    strcpy((char *)ip->value, q);
  215. X
  216. X                mvaddstr(ip->row, ip->col, ip->name);
  217. X                if(*((char *)ip->value))
  218. X                {
  219. X                    standout();                
  220. X                    addstr((char *)ip->value);
  221. X                    standend();
  222. X                }
  223. X                else
  224. X                {
  225. X                    addstr("[Not set]");
  226. X                }
  227. X                break;
  228. X                
  229. X            case ' ':        /* nextopt */
  230. X                if(ip->type == ITEM_ONOFF)
  231. X                {
  232. X                    standout();
  233. X                    if(*(ip->value))
  234. X                    {
  235. X                        *(ip->value) = 0;
  236. X                        addstr(" NO");
  237. X                    }
  238. X                    else
  239. X                    {
  240. X                        *(ip->value) = 1;
  241. X                        addstr("YES");
  242. X                    }
  243. X                    standend();
  244. X                }                
  245. X                break;
  246. X
  247. X            case CNTRL_D:
  248. X                goto breakout;
  249. X
  250. X            case KEY_UP:        /* up item */
  251. X                i = ip->col;
  252. X                do
  253. X                    ip = ip->prev;
  254. X                while(ip->col != i);
  255. X                break;
  256. X
  257. X            case KEY_DOWN:        /* down item */
  258. X                i = ip->col;
  259. X                do
  260. X                    ip = ip->next;
  261. X                while(ip->col != i);
  262. X                break;
  263. X
  264. X            case KEY_LEFT:        /* left item */
  265. X#ifdef KEY_BTAB
  266. X            case KEY_BTAB:
  267. X#endif
  268. X                ip = ip->prev;
  269. X                break;
  270. X
  271. X            case KEY_RIGHT:        /* right item */
  272. X            case TAB:
  273. X                ip = ip->next;
  274. X                break;
  275. X
  276. X            case KEY_F(1):    /* function key 1 */
  277. X                break;
  278. X
  279. X            case KEY_F(2):    /* function key 2 */
  280. X                break;
  281. X            
  282. X            case KEY_F(3):    /* function key 3 */
  283. X                break;
  284. X                
  285. X            case KEY_F(4):    /* function key 4 */
  286. X                break;
  287. X                
  288. X            case KEY_F(5):    /* function key 5 */
  289. X                break;
  290. X
  291. X            case KEY_F(6):    /* function key 6 */
  292. X                break;
  293. X                
  294. X            case KEY_F(7):    /* function key 7 */
  295. X                break;
  296. X                
  297. X            case KEY_F(8):    /* function key 8 */
  298. X                goto breakout;
  299. X
  300. X            case CNTRL_L:    /* refresh */
  301. X                touchwin(curscr);
  302. X                wrefresh(curscr);
  303. X                break;
  304. X        }
  305. X    }
  306. X
  307. Xbreakout:
  308. X
  309. X    /* do we have to reread dir ? */
  310. X
  311. X    if((strcmp(opt_wild, was_wildcard)) || (opt_wildon != was_wildon) ||
  312. X       (was_cdrom != opt_cdrom) || (was_cdnoprog != opt_cdnoprog))
  313. X    {
  314. X        free_list();            /* free malloc'ed buffers */
  315. X        init_files(PRES_NORM, NULL);    /* yes, read current dir */
  316. X    }
  317. X
  318. X    wmove(stdscr, 0, 0);            /* first line */
  319. X    wclear(stdscr);                /* clear window */
  320. X    touchwin(stdscr);
  321. X    wnoutrefresh(stdscr);
  322. X
  323. X    touchwin(cmnd_w);
  324. X    touchwin(fst_w);
  325. X    touchwin(file_w);
  326. X    if(opt_attrib)
  327. X        touchwin(attr_w);
  328. X    if(opt_labels)
  329. X        touchwin(flbl_w);
  330. X    
  331. X    resume_time();        /* restart updating time */
  332. X
  333. X    header();        /* new header */
  334. X    dis_hist();        /* display current commandline */
  335. X    fresh_files();        /* refresh files */
  336. X    attribs(1);        /* new attributes */
  337. X    update_all();        /* update complete screen */
  338. X
  339. X    cur_fktab = &sys_keys;    /* system fkey label table */
  340. X    init_flabels();
  341. X}
  342. X
  343. X/*---------------------------------------------------------------------------*
  344. X *    print a horizontal line
  345. X *---------------------------------------------------------------------------*/
  346. Xstatic void separate(int row)
  347. X{
  348. X    int i = COLS;
  349. X    unsigned char delim;
  350. X    
  351. X    move(row, 0);
  352. X
  353. X    if(opt_delimiter)
  354. X    {
  355. X        delim = opt_delimiter;        
  356. X    }
  357. X    else if(enter_alt_charset_mode && exit_alt_charset_mode &&
  358. X            *enter_alt_charset_mode && *exit_alt_charset_mode)
  359. X    {
  360. X        attron(A_ALTCHARSET);
  361. X        switch(termtype)
  362. X        {
  363. X            case TERM_HP:    /* HEWLETT-PACKARD Terminals (2392,700/9x etc) */
  364. X                delim = ';';
  365. X                break;
  366. X    
  367. X            case TERM_VT2:    /* DEC VT220 / 320 */
  368. X            case TERM_VT3:
  369. X            case TERM_PCVT:
  370. X                delim = 'q';
  371. X                break;
  372. X    
  373. X            default:    /* everything else */
  374. X                delim = DEFDELIMCH;
  375. X                break;
  376. X        }
  377. X    }
  378. X    else
  379. X    {
  380. X        delim = DEFDELIMCH;
  381. X    }
  382. X        
  383. X    while(i--)
  384. X        addch(delim);
  385. X
  386. X    if(enter_alt_charset_mode && exit_alt_charset_mode &&
  387. X           *enter_alt_charset_mode && *exit_alt_charset_mode && !opt_delimiter)
  388. X        attroff(A_ALTCHARSET);
  389. X}    
  390. X
  391. X/*---------------------------------------------------------------------------*
  392. X *    enter a string into a string variable
  393. X *---------------------------------------------------------------------------*/
  394. Xstatic char *enter_string(int row, int col, char *string, int length)
  395. X{
  396. X    static char buffer[81];
  397. X    int ccol, c;
  398. X
  399. X    strcpy(buffer, string);
  400. X    ccol = strlen(buffer);
  401. X
  402. X    for(;;)
  403. X    {
  404. X        mvaddstr(row, col, buffer);
  405. X        clrtoeol();
  406. X        
  407. X        refresh();
  408. X
  409. X        c = getch();    
  410. X
  411. X        if(c == bschar)
  412. X        {
  413. X            if(ccol > 0)
  414. X            {
  415. X                ccol--;
  416. X                buffer[ccol] = '\0';
  417. X            }
  418. X            continue;
  419. X        }
  420. X
  421. X        switch(c)
  422. X        {
  423. X            case CR:
  424. X                return(buffer);
  425. X                
  426. X            case ESC:
  427. X                return(NULL);
  428. X                
  429. X            case CNTRL_L:    /* refresh */
  430. X                touchwin(curscr);
  431. X                wrefresh(curscr);
  432. X                break;
  433. X
  434. X            default:
  435. X                if(ccol < length)
  436. X                {
  437. X                    buffer[ccol++] = c;
  438. X                    buffer[ccol] = '\0';
  439. X                }
  440. X                else
  441. X                {
  442. X                    flash();
  443. X                }
  444. X                break;
  445. X        }
  446. X    }
  447. X}
  448. X
  449. X/*----------------------- E O F -------------------------------------------*/
  450. END_OF_FILE
  451.   if test 8738 -ne `wc -c <'config.c'`; then
  452.     echo shar: \"'config.c'\" unpacked with wrong size!
  453.   fi
  454.   # end of 'config.c'
  455. fi
  456. if test -f 'cwish.h' -a "${1}" != "-c" ; then 
  457.   echo shar: Will not clobber existing file \"'cwish.h'\"
  458. else
  459.   echo shar: Extracting \"'cwish.h'\" \(13389 characters\)
  460.   sed "s/^X//" >'cwish.h' <<'END_OF_FILE'
  461. X/*---------------------------------------------------------------------------*
  462. X *
  463. X *                  cwish - windowing user friendly shell
  464. X *                  -------------------------------------
  465. X *
  466. X *               Copyright (c) 1988-1993 Hellmuth Michaelis
  467. X *
  468. X *                  Eggerstedtstr. 28
  469. X *                  22765 Hamburg
  470. X *                  Germany
  471. X *
  472. X *                  Tel:    +49 / 40 / 384298    (private)
  473. X *                  Tel:    +49 / 40 / 55903-170 (at work)
  474. X *                  e-mail: hm@hcshh.hcs.de
  475. X *
  476. X *                          --------oOo--------
  477. X *
  478. X *   This program is free software; you can redistribute it and/or modify
  479. X *   it under the terms of the GNU General Public License as published by
  480. X *   the Free Software Foundation; either version 2 of the License, or
  481. X *   (at your option) any later version.
  482. X *
  483. X *   This program is distributed in the hope that it will be useful,
  484. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  485. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  486. X *   GNU General Public License for more details.
  487. X *
  488. X *   You should have received a copy of the GNU General Public License
  489. X *   along with this program; if not, write to the Free Software
  490. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  491. X *
  492. X *---------------------------------------------------------------------------*
  493. X *
  494. X *    Last Edit-Date: [Wed Oct 20 10:04:22 1993]
  495. X *
  496. X *    -hm    conversion to curses
  497. X *    -hm    conversion to multi-windows
  498. X *    -hm    conversion to programs, files & directories
  499. X *    -hm    adding history to commandline
  500. X *    -hm    bsd porting
  501. X *    -hm    preserve dir when cd ..
  502. X *    -hm    stdlib inclusion for malloc()
  503. X *    -hm    getcwd debugging
  504. X *    -hm    fkey handling structures
  505. X *    -hm    wildcard matching cd
  506. X *    -go    ported to Ultrix
  507. X *    -hm    PAGEMASK renamed to PAGE_MSK, nameclash in SunOS 4.1.3
  508. X *    -hm    new flag USE_NCURSES
  509. X *    -hm    alternate attribute line
  510. X *
  511. X *----------------------------------------------------------------------------*/
  512. X
  513. X#ifdef USE_NCURSES
  514. X#include <ncurses.h>
  515. X#else /* !USE_NCURSES */
  516. X#ifdef ultrix
  517. X#include <cursesX.h>
  518. X#else /* !ultrix */
  519. X#include <curses.h>
  520. X#endif /* ultrix */
  521. X#endif /* USE_NCURSES */
  522. X
  523. X#include <ctype.h>
  524. X#include <errno.h>
  525. X#include <fcntl.h>
  526. X#include <grp.h>
  527. X#include <pwd.h>
  528. X#include <stdio.h>
  529. X#include <stdlib.h>
  530. X#include <string.h>
  531. X#include <strings.h>
  532. X#include <term.h>
  533. X#include <time.h>
  534. X#include <unistd.h>
  535. X#include <utmp.h>
  536. X#include <sys/dir.h>
  537. X#include <sys/param.h>
  538. X#include <sys/stat.h>
  539. X#include <sys/types.h>
  540. X
  541. X#ifdef MAIN
  542. X#define EXTERNAL
  543. X#else
  544. X#define EXTERNAL extern
  545. X#endif
  546. X
  547. X#define EXPSEL    '%'    /* expand selection character in commandline */
  548. X
  549. X#define DEFDELIMCH '-'    /* default char used for horizontal delimiting lines */
  550. X
  551. X/* screen */
  552. X
  553. X#define C_HEAD     0    /* copyright header line */
  554. X#define C_LINE     1    /* command entry line */
  555. X#define C_SEP     2    /* separator line between command & file display */
  556. X#define C_HEIGHT 3    /* commandline height in lines */
  557. X
  558. X#define F_BEG     0    /* first line of file window */
  559. X
  560. X#define A_SEP     0    /* separator line between file display & status line */
  561. X#define A_LINE     1    /* attributes line */
  562. X
  563. X#define CURDIRW    11    /* F_CURDIR: current dir string width */
  564. X#define ENTRYSW    9    /* F_CURDIR: entries string width */
  565. X#define ENTRYCW    4    /* F_CURDIR: entries count width */
  566. X
  567. X/* normal attribute line */
  568. X
  569. X#define PP_PERM    0        /* position of permission string */
  570. X
  571. X#define PP_DATE    11        /* position of date string */
  572. X
  573. X#define PS_SIZE    26        /* position description string */
  574. X#define ST_SIZE    "Size:"        /* description */
  575. X#define PP_SIZE    PS_SIZE+6    /* position parameter string */
  576. X
  577. X#define PS_LINK    42        /* position description string */
  578. X#define ST_LINK    "Link:"        /* description */
  579. X#define PP_LINK    PS_LINK+6    /* position parameter string */
  580. X
  581. X#define PS_USER    52        /* position description string */
  582. X#define ST_USER    "Usr:"        /* description */
  583. X#define PP_USER    PS_USER+5    /* position parameter string */
  584. X
  585. X#define PS_GRUP    66        /* position description string */
  586. X#define ST_GRUP    "Grp:"        /* description */
  587. X#define PP_GRUP    PS_GRUP+5    /* position parameter string */
  588. X
  589. X/* alternate attribute line */
  590. X
  591. X#define APS_ADATE    0        /* position description string */
  592. X#define AST_ADATE    "Acc:"        /* description */
  593. X#define APP_ADATE    APS_ADATE+5    /* position parameter string */
  594. X
  595. X#define APS_MDATE    20         /* position description string */
  596. X#define AST_MDATE    "Mod:"        /* description */
  597. X#define APP_MDATE    APS_MDATE+5    /* position parameter string */
  598. X
  599. X#define APS_CDATE    40        /* position description string */
  600. X#define AST_CDATE    "Chg:"        /* description */
  601. X#define APP_CDATE    APS_CDATE+5    /* position parameter string */
  602. X
  603. X#define APS_INODE    60        /* position description string */
  604. X#define AST_INODE    "Ino:"        /* description */
  605. X#define APP_INODE    APS_INODE+5    /* position parameter string */
  606. X
  607. X#define STOPS      30    /* # of positions for filename on screen */
  608. X#define MINSPACE 2    /* minimum space between two filenames */
  609. X#define STARTCOL 7    /* start column in a row */
  610. X
  611. X#ifndef TRUE
  612. X#define TRUE    1    /* TRUE */
  613. X#define FALSE    0    /* not TRUE */
  614. X#endif
  615. X
  616. X#define ABORT    -1    /* wildmatch */
  617. X#define GOOD    TRUE    /* good return */
  618. X#define BAD      FALSE    /* bad return */
  619. X
  620. X#define FIRST    0x100    /* first entry of a file-page */
  621. X#define PAGE_MSK 0x0ff    /* for reading just the page */
  622. X
  623. X#define CR    0x0d    /* some characters */
  624. X#define LF    0x0a
  625. X#define TAB    0x09
  626. X#define BS    0x08
  627. X#define DEL    0x7f
  628. X#define SPACE    0x20
  629. X#define BEL    0x07
  630. X#define ESC    0x1b
  631. X
  632. X/* keycodes for cursor motion */
  633. X
  634. X#define    K_UP    0x10    /* ^P */
  635. X#define K_DOWN    0x0e    /* ^N */
  636. X#define    K_LEFT    0x02    /* ^B */
  637. X#define    K_RIGHT    0x06    /* ^F */
  638. X
  639. X#define K_TAB    0x09    /* tab */
  640. X
  641. X#define K_NEXT    0x16    /* ^V */
  642. X#define K_PREV    0x1a    /* ^Z */
  643. X
  644. X#define K_QUIT    0x04    /* ^D */
  645. X#define K_REF    0x0c    /* ^L */
  646. X
  647. X#define K_MARK    0x01    /* ^A */
  648. X#define    K_ECHO    0x17    /* ^W */
  649. X#define K_UMARK    0x15    /* ^U */
  650. X
  651. X#define HISLINES    32    /* no. of lines in history buffer */
  652. X#define HISLNLEN    512    /* length of one history line */
  653. X
  654. X/* terminal types */
  655. X
  656. X#define TERM_DUMB        0    /* dumb whatsoever */
  657. X#define TERM_HP            1    /* Hewlett Packard 2392 or 700/9x */
  658. X#define TERM_VT1        2    /* DEC VT100 */
  659. X#define TERM_VT2        3    /* DEC VT220 */
  660. X#define TERM_VT3        4    /* DEC VT320 */
  661. X#define TERM_PCVT        5    /* 386BSD pcvt driver */
  662. X#define TERM_HPX        6    /* hpterm X11 terminal emulator */
  663. X
  664. X/* preserve options */
  665. X
  666. X#define PRES_NO        0        /* don't preserve anything */
  667. X#define PRES_NORM    1        /* try "normal" position preserve */
  668. X#define PRES_DD        2        /* jump to cur dir after cd .. */
  669. X
  670. X/* one file */
  671. X
  672. Xstruct onefile {        /* structure for one directory entry */
  673. X    off_t    osiz;        /* file size */
  674. X    uid_t    ousr;        /* user */
  675. X    gid_t    ogrp;        /* group */
  676. X    nlink_t    olinks;        /* no of hard links */    
  677. X    time_t    oatime;        /* access time */
  678. X    time_t    octime;        /* last file status chage time */
  679. X    ino_t    oinode;        /* inode */
  680. X    char    *onam;        /* filename, malloc'ed */
  681. X    char    oslink;        /* softlink flag */
  682. X    char    oprm[16];    /* permissions */
  683. X    char    odat[15];    /* modification time */
  684. X    int    orow;        /* relative row to display item */
  685. X    int    ocol;        /* relative column to display item */
  686. X    int    tag;        /* flag for tagging files */
  687. X    int    page;        /* page and number for display window */
  688. X    struct onefile *next;    /* ptr to next entry */
  689. X    struct onefile *prev;    /* prt to previous entry */
  690. X};
  691. X
  692. X/* onam[0] contains the entry type, which can be:    */
  693. X
  694. X#define ISDIR    '1'
  695. X#define    ISPROG    '2'
  696. X#define    ISDATA    '3'
  697. X#define    ISCHAR    '4'
  698. X#define    ISBLOCK    '5'
  699. X#define    ISPIPE    '6'
  700. X#define ISSOCK    '7'
  701. X#define ISUNKN    '8'
  702. X
  703. X#define OPTSLEN    60        /* option string length */
  704. X
  705. X#define WILDCHARS "\\?*["    /* special meaning chars */
  706. X
  707. X/* fkey labels */
  708. X
  709. Xstruct fk_tab {
  710. X    char *label_16;        /* HP Terminal Labels */
  711. X    char *label_8;        /* DEC (and others) Terminal Labels */
  712. X};
  713. X
  714. Xextern struct fk_tab sys_keys[];
  715. X
  716. X#ifdef MAIN
  717. X
  718. Xchar *hislines[HISLINES];    /* array of history line pointers */
  719. Xint  cur_his = 0;        /* current history line */
  720. Xchar cbuff[HISLNLEN+16];    /* command buffer */
  721. X
  722. Xchar counter[5] = "\0";        /* entrycount as string */
  723. Xchar cur_path[1024];        /* current path */
  724. Xchar errorline[256];        /* error line if errorflag == 1 */
  725. Xchar headerline[256];        /* headerline for copyright etc */
  726. X
  727. Xint stops[STOPS];        /* table of stop points on row */
  728. X
  729. Xint tagsize = 0;        /* sum of sizes of tagged files */
  730. X
  731. Xstruct onefile *cur_file = NULL;/* the CURRENT highlighted filename */
  732. Xstruct onefile *first = NULL;    /* init dir-list head-ptr */
  733. Xstruct onefile *last = NULL;    /* init dir-list tail-ptr */
  734. X
  735. Xint maxfnleng = 0;        /* length of longest filename of this dir */
  736. Xint opt_attrib = 1;        /* display attribute line */
  737. Xint opt_labels = 0;        /* use virtual f-key labels in last line */
  738. Xint opt_point  = 0;        /* display current dir in file window */
  739. Xint opt_preserve = 0;        /* initially preserve dirs when cd .. */
  740. Xint opt_links = 0;        /* initially show files not links */
  741. Xint opt_return = 1;        /* press any key to continue */
  742. Xunsigned char opt_delimiter = 0;/* window delimiter character */
  743. Xint opt_wildon = 0;        /* no wildcarding yet */
  744. Xchar opt_wild[OPTSLEN+1];    /* file window wildcard spec */
  745. Xchar opt_edit[OPTSLEN+1];    /* user sepecified editor */
  746. Xchar opt_more[OPTSLEN+1];    /* user sepecified pager */
  747. Xint opt_cdrom = 0;        /* cdrom special filename processing */
  748. Xint opt_cdnoprog = 0;        /* cdrom, convert executables to data */
  749. Xint opt_dotnames = 1;        /* display filenames starting with dot */
  750. Xint opt_tagmove = 1;        /* move to next filename after tagging */
  751. Xint opt_altattr = 0;        /* alternate attribute line */
  752. X
  753. X#else /* !MAIN */
  754. X
  755. Xextern char *hislines[];
  756. Xextern int  cur_his;
  757. X
  758. Xextern char cbuff[];
  759. X
  760. Xextern char counter[];
  761. Xextern char cur_path[];
  762. Xextern char errorline[];
  763. Xextern char headerline[];
  764. X
  765. Xextern int stops[];
  766. X
  767. Xextern int tagsize;
  768. X
  769. Xextern struct onefile *cur_file;
  770. Xextern struct onefile *first;
  771. Xextern struct onefile *last;
  772. X
  773. Xextern int maxfnleng;
  774. Xextern int opt_attrib;
  775. Xextern int opt_labels;
  776. Xextern int opt_point;
  777. Xextern int opt_preserve;
  778. Xextern int opt_links;
  779. Xextern int opt_return;
  780. Xextern unsigned char opt_delimiter;
  781. Xextern opt_wildon;
  782. Xextern char opt_wild[];
  783. Xextern char opt_edit[];
  784. Xextern char opt_more[];
  785. Xextern int opt_cdrom;
  786. Xextern int opt_cdnoprog;
  787. Xextern int opt_dotnames;
  788. Xextern int opt_tagmove;
  789. Xextern int opt_altattr;
  790. X
  791. X#endif /* MAIN */
  792. X
  793. XEXTERNAL char bschar;        /* backspace */
  794. X
  795. XEXTERNAL WINDOW *attr_w;    /* attributes display window (separation,attributes) */
  796. XEXTERNAL WINDOW *cmnd_w;    /* command line window (copyright,command,separation) */
  797. XEXTERNAL WINDOW *file_w;    /* files display window (file names) */
  798. XEXTERNAL WINDOW *fst_w;        /* files status window (cur dir, entries) */
  799. XEXTERNAL WINDOW *flbl_w;    /* function key labels */
  800. X
  801. XEXTERNAL char *envhome;        /* ptr to HOME - env var */
  802. XEXTERNAL char *envmore;        /* ptr to PAGER - env var */
  803. XEXTERNAL char *envedit;        /* ptr to EDITOR - env var */
  804. XEXTERNAL char *term_string;    /* terminal type string from environment */
  805. X
  806. XEXTERNAL int termtype;        /* flag what terminal category we are on */
  807. X
  808. XEXTERNAL struct onefile *scr_beg;/* ptr to first filename on screen */
  809. XEXTERNAL struct onefile *scr_end;/* ptr to last filename on screen */
  810. X
  811. XEXTERNAL int cur_page;        /* current file window page */
  812. XEXTERNAL int errorflag;        /* if error string is in header line */
  813. XEXTERNAL int fileheight;    /* height of filewindow */
  814. XEXTERNAL struct fk_tab (*cur_fktab)[]; /* current fkey label table */
  815. XEXTERNAL int iscdfs;        /* flag, true if we are on a cdrom filesys */
  816. X
  817. Xvoid attribs ( int flag );
  818. Xvoid bol_line ( void );
  819. Xint cd( char *string );
  820. Xvoid clear_toeol ( void );
  821. Xvoid close_cdir ( void );
  822. Xvoid clrerror ( void );
  823. Xint cmdline ( int c );
  824. Xvoid complete ( void );
  825. Xvoid config( void );
  826. Xint cr_on_files ( void );
  827. Xint curcol ( void );
  828. Xvoid cur_blink ( struct onefile *current );
  829. Xvoid cur_inv ( struct onefile *current );
  830. Xvoid cur_norm ( struct onefile *current );
  831. Xvoid del_char ( void );
  832. Xvoid dis_hist ( void );
  833. Xvoid edit_current ( void );
  834. Xvoid eol_line ( void );
  835. Xvoid error ( char *str );
  836. Xvoid exec_command ( char *cline );
  837. Xvoid expsel ( char *p );
  838. Xvoid fatal ( char *str );
  839. Xint fill_list ( void );
  840. Xvoid fini_flabels ( void );
  841. Xint firstfile ( void );
  842. Xvoid fnclabel ( int n, char *string );
  843. Xvoid free_list ( void );
  844. Xvoid fresh_files ( void );
  845. Xchar *group_from_gid ( gid_t gid, int size );
  846. Xvoid handlebs ( void );
  847. Xvoid handlecr ( void );
  848. Xvoid header ( void );
  849. Xvoid help ( void );
  850. Xvoid h_files ( void );
  851. Xvoid h_line ( void );
  852. Xvoid init_files ( int preserve, char *dirname );
  853. Xvoid init_flabels ( void );
  854. Xvoid init_header ( void );
  855. Xvoid init_history ( void );
  856. Xvoid init_screen ( void );
  857. Xvoid init_time ( void );
  858. Xvoid is_tagged ( struct onefile *current );
  859. Xint lastfile ( void );
  860. Xvoid left_line ( void );
  861. Xint main ( int argc, char *argv[] );
  862. Xvoid move_down ( void );
  863. Xvoid move_hmdn ( void );
  864. Xvoid move_home ( void );
  865. Xvoid move_left ( void );
  866. Xvoid move_right ( void );
  867. Xvoid move_up ( void );
  868. Xvoid name_echo ( void );
  869. Xint nextfile ( void );
  870. Xvoid next_line ( void );
  871. Xvoid next_page ( void );
  872. Xint prevfile ( void );
  873. Xvoid prev_line ( void );
  874. Xvoid prev_page ( void );
  875. Xvoid readrc ( void );
  876. Xvoid resume_time ( void );
  877. Xvoid right_line ( void );
  878. Xvoid save_line ( void );
  879. Xvoid sepaline ( struct _win_st *window );
  880. Xvoid set_termtype ( void );
  881. Xstruct onefile *store ( struct onefile *new, struct onefile *top );
  882. Xvoid suspend_time ( void );
  883. Xvoid tag_current ( struct onefile *current );
  884. Xvoid timeout_hdlr ( int sig );
  885. Xvoid untag_all ( void );
  886. Xvoid update_all ( void );
  887. Xvoid update_files ( void );
  888. Xvoid usage ( void );
  889. Xchar *user_from_uid ( uid_t uid, int size );
  890. Xint wildmat( char *text, char *p );
  891. Xvoid yank ( void );
  892. X
  893. X/*---------------------------------- EOF -------------------------------------*/
  894. END_OF_FILE
  895.   if test 13389 -ne `wc -c <'cwish.h'`; then
  896.     echo shar: \"'cwish.h'\" unpacked with wrong size!
  897.   fi
  898.   # end of 'cwish.h'
  899. fi
  900. if test -f 'files.c' -a "${1}" != "-c" ; then 
  901.   echo shar: Will not clobber existing file \"'files.c'\"
  902. else
  903.   echo shar: Extracting \"'files.c'\" \(10569 characters\)
  904.   sed "s/^X//" >'files.c' <<'END_OF_FILE'
  905. X/*---------------------------------------------------------------------------*
  906. X *
  907. X *                  cwish - windowing user friendly shell
  908. X *                  -------------------------------------
  909. X *
  910. X *              (c) Copyright Hellmuth Michaelis 1989 - 1993
  911. X *
  912. X *                  Eggerstedtstr. 28
  913. X *                  22765 Hamburg
  914. X *                  Germany
  915. X *
  916. X *                  Tel:    +49 / 40 / 384298    (private)
  917. X *                  Tel:    +49 / 40 / 55903-170 (at work)
  918. X *                  e-mail: hm@hcshh.hcs.de
  919. X *
  920. X *           All rights are reserved except as explicitly granted
  921. X *                  by written permission of the author.
  922. X *
  923. X *             See the file COPYING, distributed with cwish, for
  924. X *                  restriction and warranty information
  925. X *
  926. X *---------------------------------------------------------------------------*
  927. X *
  928. X *    Last Edit-Date: [Wed Oct 20 11:08:55 1993]
  929. X *
  930. X *    -hm    conversion to curses
  931. X *    -hm    new sorting order
  932. X *    -hm    displaying file count
  933. X *    -hm    optimizing .....
  934. X *    -hm    wildcard filenames
  935. X *    -hm    cdrom processing option
  936. X *    -hm    cdrom programs to files option
  937. X *    -go    ported to Ultrix
  938. X *    -hm    portability definitions, statfs portability
  939. X *    -hm    NOSTATFS for SunOS 4.1.3
  940. X *    -hm    more file stat info for alternate attrib line
  941. X *    -hm    malloced file name for struct onefile
  942. X *
  943. X *----------------------------------------------------------------------------*/
  944. X
  945. X#include "cwish.h"        /* global include file */
  946. X
  947. X#ifdef ultrix
  948. X
  949. X#include <sys/fs_types.h>
  950. X
  951. X#define S_IFLNK        0120000        /* symbolic link */
  952. X#define S_IFSOCK    0140000        /* socket */
  953. X#define _S_IFLNK    S_IFLNK
  954. X#define _S_IFSOCK    S_IFSOCK
  955. X
  956. X/* macro to test for symbolic link */
  957. X#define S_ISLNK( mode )        (((mode) & _S_IFLNK) == _S_IFLNK)
  958. X
  959. X/* macro to test for socket */
  960. X#define S_ISSOCK( mode )    (((mode) & _S_IFSOCK) == _S_IFSOCK)
  961. X
  962. X#else /* !ultrix */
  963. X
  964. X#ifndef __386BSD__
  965. X
  966. X#include <sys/vfs.h>
  967. X
  968. X/* some SYSVR4 don't know these */
  969. X
  970. X#ifndef S_ISLNK
  971. X#define S_ISLNK(_Mode)        (((_Mode) & S_IFMT) == S_IFLNK)
  972. X#endif
  973. X
  974. X#ifndef S_ISSOCK
  975. X#define S_ISSOCK(_Mode)        (((_Mode) & S_IFMT) == S_IFSOCK)
  976. X#endif
  977. X
  978. X#endif /* __386BSD__ */
  979. X
  980. X#endif /* ultrix */
  981. X
  982. X#include <sys/mount.h>
  983. X
  984. Xstatic int  pia[] = {S_IFDIR,S_IREAD,S_IWRITE,S_IEXEC,040,020,010,04,02,01};
  985. Xstatic char pca[] = "drwxrwxrwx";
  986. X
  987. X/*---------------------------------------------------------------------------*
  988. X *    create a doubly linked list in sorted order, return pointer to new
  989. X *    first element of list
  990. X *---------------------------------------------------------------------------*/
  991. Xstruct onefile *store
  992. X(register struct onefile *new,    /* new entry to store into list */
  993. X register struct onefile *top)    /* current first entry in list */
  994. X{
  995. X    register struct onefile *old,*p;
  996. X    
  997. X    if(last == NULL)    /* enter very first element ? */
  998. X    {
  999. X        new->next = NULL;
  1000. X        new->prev = NULL;
  1001. X        last = new;    /* init last */
  1002. X        return(new);    /* return new first */
  1003. X    }
  1004. X    p = top;        /* p = old first element */
  1005. X    old = NULL;
  1006. X    while(p)
  1007. X    {
  1008. X        if((strcmp(p->onam,new->onam)) < 0)    /* current less new ? */
  1009. X        {
  1010. X            old = p;
  1011. X            p = p->next;
  1012. X        }
  1013. X        else
  1014. X        {    /* current >= new */
  1015. X        
  1016. X            if(p->prev)
  1017. X            {
  1018. X                p->prev->next = new;
  1019. X                new->next = p;
  1020. X                new->prev = p->prev;
  1021. X                p->prev = new;
  1022. X                return(top);
  1023. X            }
  1024. X            new->next = p;
  1025. X            new->prev = NULL;
  1026. X            p->prev = new;
  1027. X            return(new);
  1028. X        }
  1029. X    }
  1030. X    old->next = new;
  1031. X    new->next = NULL;
  1032. X    new->prev = old;
  1033. X    last = new;
  1034. X    return(first);
  1035. X}
  1036. X
  1037. X/*---------------------------------------------------------------------------*
  1038. X *    read current directory and build up a doubly linked sorted list
  1039. X *---------------------------------------------------------------------------*/
  1040. Xint fill_list(void)
  1041. X{
  1042. X    register struct direct *dp;
  1043. X    register struct onefile *new_entry;
  1044. X    register struct tm *tp;
  1045. X    register DIR *dirp;
  1046. X    
  1047. X    static struct stat fdbuffer;
  1048. X    static char templine[MAXPATHLEN+2];
  1049. X
  1050. X    int templeng;
  1051. X    int flcnt = 0;
  1052. X    int sret;
  1053. X
  1054. X    maxfnleng = 0;        /* init global variables */    
  1055. X
  1056. X    iscdfs = 0;        /* no cdrom filesys */
  1057. X
  1058. X#ifndef NOSTATFS
  1059. X    
  1060. X    if(opt_cdrom)
  1061. X    {
  1062. X
  1063. X#ifdef __386BSD__
  1064. X
  1065. X        struct statfs statfsb;
  1066. X    /* the 386BSD way, this also seems to work for SunOS 4.1.x */
  1067. X        if((statfs(".", &statfsb)==0) && (statfsb.f_type==MOUNT_ISOFS))
  1068. X
  1069. X#else /* ! __386BSD__ */
  1070. X
  1071. X#ifdef ultrix
  1072. X
  1073. X        struct fs_data statfsb;
  1074. X    /* the ULTRIX way ... */
  1075. X        if((statfs(".", &statfsb)==0) && (statfsb.fd_req.fstype==GT_CDFS))
  1076. X
  1077. X#else /* ! ultrix */
  1078. X
  1079. X        struct statfs statfsb;
  1080. X    /* the HPUX way ... */
  1081. X        if((statfs(".", &statfsb)==0) && (statfsb.f_fsid[1]==MOUNT_CDFS))
  1082. X
  1083. X#endif /* ultrix */
  1084. X
  1085. X#endif /* __386BSD__ */
  1086. X
  1087. X        iscdfs = 1;
  1088. X    }
  1089. X        
  1090. X#endif /* NOSTATFS */
  1091. X
  1092. X    if((dirp = opendir(".")) == NULL)
  1093. X        return(-1);    /* cannot open directory */
  1094. X
  1095. X    for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
  1096. X    {
  1097. X          flcnt++;            /* increment file count */
  1098. X
  1099. X         if(!opt_point)            /* display dot ? */
  1100. X         {
  1101. X            if((*(dp->d_name) == '.') && (*(dp->d_name+1) == '\0'))
  1102. X                continue;
  1103. X        }
  1104. X
  1105. X        if(!opt_dotnames)        /* display dot-names ? */
  1106. X        {
  1107. X            if((*(dp->d_name) == '.') && (*(dp->d_name+1) != '.') && (*(dp->d_name+1) != '\0'))
  1108. X                continue;
  1109. X        }
  1110. X        
  1111. X        if((new_entry = (struct onefile *) malloc(sizeof(struct onefile))) == NULL)
  1112. X        {
  1113. X            fatal("files.c, fill_list(): structure onefile malloc failed");
  1114. X        }
  1115. X
  1116. X        new_entry->oslink = 0;        /* init softlink flag */
  1117. X        
  1118. X        if(opt_links)            /* detect SOFT links ? */
  1119. X        {
  1120. X            sret = 0;        /* init return */
  1121. X
  1122. X            if((lstat(dp->d_name, &fdbuffer)) < 0)
  1123. X            {
  1124. X                free(new_entry);    /* lstat failed */
  1125. X                continue;        /* next one .. */
  1126. X            }
  1127. X
  1128. X            if(S_ISLNK(fdbuffer.st_mode))    /* have a soft link ? */
  1129. X            {
  1130. X                new_entry->oslink = 1;    /* mark as soft link */
  1131. X                sret = stat(dp->d_name, &fdbuffer); /* and get status */
  1132. X            }
  1133. X        }
  1134. X        else
  1135. X        {
  1136. X            sret = stat(dp->d_name, &fdbuffer);    /* get status */
  1137. X        }
  1138. X
  1139. X        if(sret < 0)            /* return from stat bad ? */
  1140. X        {
  1141. X            free(new_entry);    /* next entry ... */
  1142. X            continue;
  1143. X        }
  1144. X        else    /* got status, fill in from stat buffer */
  1145. X        {
  1146. X            register int j;
  1147. X            
  1148. X            /* size, userid, groupid, hardlinks, inode */
  1149. X            
  1150. X            new_entry->osiz = fdbuffer.st_size;
  1151. X            new_entry->ousr = fdbuffer.st_uid;
  1152. X            new_entry->ogrp = fdbuffer.st_gid;
  1153. X            new_entry->olinks = fdbuffer.st_nlink;
  1154. X            new_entry->oinode = fdbuffer.st_ino;
  1155. X
  1156. X            /* permissions */
  1157. X            
  1158. X            for(j = 0; j < 10; j++)
  1159. X            {
  1160. X                if(fdbuffer.st_mode & pia[j])
  1161. X                    new_entry->oprm[j] = pca[j];
  1162. X                else
  1163. X                    new_entry->oprm[j] = '-';
  1164. X            }
  1165. X            new_entry->oprm[j] = '\0';
  1166. X            
  1167. X            /* type of file -> templine[0] */
  1168. X            
  1169. X            if(S_ISREG(fdbuffer.st_mode))
  1170. X            {
  1171. X                if(opt_wildon && (wildmat(dp->d_name, opt_wild) != TRUE))
  1172. X                {
  1173. X                    free(new_entry);
  1174. X                    continue;
  1175. X                }
  1176. X                new_entry->oprm[0] = '-';
  1177. X                if((new_entry->oprm[3] == 'x') ||
  1178. X                           (new_entry->oprm[6] == 'x') ||
  1179. X                           (new_entry->oprm[9] == 'x'))
  1180. X                        {
  1181. X                            if(iscdfs && opt_cdnoprog)
  1182. X                            {
  1183. X                        new_entry->oprm[3] = '-';
  1184. X                                new_entry->oprm[6] = '-';
  1185. X                        new_entry->oprm[9] = '-';
  1186. X                        templine[0] = ISDATA;
  1187. X                    }
  1188. X                    else
  1189. X                    {
  1190. X                                   templine[0] = ISPROG;
  1191. X                            }
  1192. X                        }
  1193. X                else
  1194. X                    templine[0] = ISDATA;
  1195. X                if((fdbuffer.st_mode & S_IFMT) == S_ISUID)
  1196. X                    new_entry->oprm[3] = 's';
  1197. X                if((fdbuffer.st_mode & S_IFMT) == S_ISGID)
  1198. X                    new_entry->oprm[6] = 's';
  1199. X            }
  1200. X            else if(S_ISDIR(fdbuffer.st_mode))
  1201. X            {
  1202. X                if(opt_wildon)
  1203. X                {
  1204. X                    flcnt--;
  1205. X                }
  1206. X                templine[0] = ISDIR;
  1207. X                new_entry->oprm[0] = 'd';
  1208. X            }
  1209. X            else if(S_ISCHR(fdbuffer.st_mode))
  1210. X            {            
  1211. X                if(opt_wildon && (wildmat(dp->d_name, opt_wild) != TRUE))
  1212. X                {
  1213. X                    free(new_entry);
  1214. X                    continue;
  1215. X                }
  1216. X                templine[0] = ISCHAR;
  1217. X                new_entry->oprm[0] = 'c';
  1218. X            }
  1219. X            else if(S_ISBLK(fdbuffer.st_mode))
  1220. X            {
  1221. X                if(opt_wildon && (wildmat(dp->d_name, opt_wild) != TRUE))
  1222. X                {
  1223. X                    free(new_entry);
  1224. X                    continue;
  1225. X                }
  1226. X                templine[0] = ISBLOCK;
  1227. X                new_entry->oprm[0] = 'b';
  1228. X            }
  1229. X            else if(S_ISFIFO(fdbuffer.st_mode))
  1230. X            {
  1231. X                if(opt_wildon && (wildmat(dp->d_name, opt_wild) != TRUE))
  1232. X                {
  1233. X                    free(new_entry);
  1234. X                    continue;
  1235. X                }
  1236. X                templine[0] = ISPIPE;
  1237. X                new_entry->oprm[0] = 'p';
  1238. X            }
  1239. X            else if(S_ISSOCK(fdbuffer.st_mode))
  1240. X            {
  1241. X                if(opt_wildon && (wildmat(dp->d_name, opt_wild) != TRUE))
  1242. X                {
  1243. X                    free(new_entry);
  1244. X                    continue;
  1245. X                }
  1246. X                templine[0] = ISSOCK;
  1247. X                new_entry->oprm[0] = 'n';
  1248. X            }
  1249. X            else
  1250. X            {
  1251. X                if(opt_wildon && (wildmat(dp->d_name, opt_wild) != TRUE))
  1252. X                {
  1253. X                    free(new_entry);
  1254. X                    continue;
  1255. X                }
  1256. X                templine[0] = ISUNKN; /* unknown */
  1257. X                new_entry->oprm[0] = 'u';
  1258. X            }
  1259. X            templine[1] = '\0'; /* terminate templine */
  1260. X
  1261. X            /* file time */
  1262. X            
  1263. X            tp = localtime(&(fdbuffer.st_mtime));
  1264. X
  1265. X#ifdef DATE_US
  1266. X            /* us date string */
  1267. X            sprintf(new_entry->odat,"%02d/%02d/%02d %02d:%02d",
  1268. X                (tp->tm_mon)+1,tp->tm_mday,tp->tm_year,
  1269. X                tp->tm_hour,tp->tm_min);
  1270. X#else
  1271. X            /* german date string */
  1272. X            sprintf(new_entry->odat,"%02d.%02d.%02d %02d:%02d",
  1273. X                tp->tm_mday,(tp->tm_mon)+1,tp->tm_year,
  1274. X                tp->tm_hour,tp->tm_min);
  1275. X#endif /* DATE_US  */
  1276. X
  1277. X            new_entry->oatime = fdbuffer.st_atime;
  1278. X            new_entry->octime = fdbuffer.st_ctime;
  1279. X
  1280. X            /* misc init */
  1281. X            
  1282. X            new_entry->tag = 0;    /* clear tag-field */
  1283. X            new_entry->page = -1;    /* page # unknown */
  1284. X
  1285. X            /* new max filename length */
  1286. X            
  1287. X            templeng = strlen(dp->d_name);    /* get name length */
  1288. X            if(templeng > maxfnleng)    /* new max filename length ? */
  1289. X                maxfnleng = templeng;    /* yes */
  1290. X
  1291. X            /* cat templine + filename */
  1292. X
  1293. X            strcat(templine, dp->d_name);    /* file name */
  1294. X
  1295. X            /* alloc filename memory and copy name into it */
  1296. X
  1297. X            if((new_entry->onam = (char *)malloc(strlen(templine) + 1)) == NULL)
  1298. X            {
  1299. X                fatal("files.c, fill_list(): malloc filename string memory failed");
  1300. X            }
  1301. X
  1302. X            strcpy(new_entry->onam, templine);    
  1303. X
  1304. X            /* sort entry into linked list */
  1305. X            
  1306. X            first = store(new_entry,first);
  1307. X        }
  1308. X    }
  1309. X    closedir(dirp);                /* close current dir */
  1310. X    sprintf(counter,"%4d",flcnt);        /* entries counter */
  1311. X    return(0);                /* ok return */
  1312. X}
  1313. X
  1314. X/*---------------------------------------------------------------------------*
  1315. X *    free the current malloc'ed list
  1316. X *---------------------------------------------------------------------------*/
  1317. Xvoid free_list(void)
  1318. X{
  1319. X    register struct onefile *dir;
  1320. X    register struct onefile *tmp;        
  1321. X
  1322. X    tagsize = 0;            /* reset any tags/marks size */
  1323. X    
  1324. X    dir = first;            /* start of linked list */
  1325. X
  1326. X    while(dir)            /* free all */
  1327. X    {
  1328. X        tmp = dir->next;    /* save ptr to next entry */
  1329. X        free(dir->onam);    /* free filename space */
  1330. X        free(dir);        /* free struct space */
  1331. X        dir = tmp;        /* ptr = ptr to next entry */
  1332. X    }
  1333. X    first = NULL;            /* first ptr = NULL */
  1334. X    last = NULL;            /* last ptr = NULL */
  1335. X}
  1336. X/*---------------------------------- EOF -------------------------------------*/
  1337. END_OF_FILE
  1338.   if test 10569 -ne `wc -c <'files.c'`; then
  1339.     echo shar: \"'files.c'\" unpacked with wrong size!
  1340.   fi
  1341.   # end of 'files.c'
  1342. fi
  1343. if test -f 'header.c' -a "${1}" != "-c" ; then 
  1344.   echo shar: Will not clobber existing file \"'header.c'\"
  1345. else
  1346.   echo shar: Extracting \"'header.c'\" \(8632 characters\)
  1347.   sed "s/^X//" >'header.c' <<'END_OF_FILE'
  1348. X/*---------------------------------------------------------------------------*
  1349. X *
  1350. X *                  cwish - windowing user friendly shell
  1351. X *                  -------------------------------------
  1352. X *
  1353. X *               Copyright (c) 1988-1993 Hellmuth Michaelis
  1354. X *
  1355. X *                  Eggerstedtstr. 28
  1356. X *                  22765 Hamburg
  1357. X *                  Germany
  1358. X *
  1359. X *                  Tel:    +49 / 40 / 384298    (private)
  1360. X *                  Tel:    +49 / 40 / 55903-170 (at work)
  1361. X *                  e-mail: hm@hcshh.hcs.de
  1362. X *
  1363. X *                          --------oOo--------
  1364. X *
  1365. X *   This program is free software; you can redistribute it and/or modify
  1366. X *   it under the terms of the GNU General Public License as published by
  1367. X *   the Free Software Foundation; either version 2 of the License, or
  1368. X *   (at your option) any later version.
  1369. X *
  1370. X *   This program is distributed in the hope that it will be useful,
  1371. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1372. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1373. X *   GNU General Public License for more details.
  1374. X *
  1375. X *   You should have received a copy of the GNU General Public License
  1376. X *   along with this program; if not, write to the Free Software
  1377. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1378. X *
  1379. X *---------------------------------------------------------------------------*
  1380. X *
  1381. X *    Last Edit-Date: [Tue Oct 19 13:46:54 1993]
  1382. X *
  1383. X *    -hm    converting to curses and multiwindows
  1384. X *    -hm    separation line in attribs window
  1385. X *    -hm    vt220 support
  1386. X *    -hm    show time in header
  1387. X *    -hm    hpterm / zero pointers in hpux 9.0
  1388. X *    -hm    alternate attrib line
  1389. X *    -hm    inode in alternate attr line
  1390. X *
  1391. X *----------------------------------------------------------------------------*/
  1392. X
  1393. X#include "cwish.h"
  1394. X
  1395. X/*---------------------------------------------------------------------------*
  1396. X *    print a horizontal separation line based on delimiter-character
  1397. X *---------------------------------------------------------------------------*/
  1398. Xvoid sepaline(WINDOW *window)     
  1399. X{
  1400. X    int i = COLS;
  1401. X    unsigned char delim;
  1402. X    
  1403. X    if(window == cmnd_w)
  1404. X        wmove(window, 2, 0);
  1405. X    else if(window == attr_w)
  1406. X        wmove(window, 0, 0);
  1407. X    else
  1408. X        return;
  1409. X
  1410. X    if(opt_delimiter)
  1411. X    {
  1412. X        delim = opt_delimiter;        
  1413. X    }
  1414. X    else if(enter_alt_charset_mode && exit_alt_charset_mode &&
  1415. X        *enter_alt_charset_mode && *exit_alt_charset_mode)
  1416. X    {
  1417. X        wattron(window, A_ALTCHARSET);
  1418. X        switch(termtype)
  1419. X        {
  1420. X            case TERM_HP:    /* HEWLETT-PACKARD Terminals (2392,700/9x etc) */
  1421. X                delim = ';';
  1422. X                break;
  1423. X    
  1424. X            case TERM_VT2:    /* DEC VT220 / 320 */
  1425. X            case TERM_VT3:
  1426. X            case TERM_PCVT:
  1427. X                delim = 'q';
  1428. X                break;
  1429. X    
  1430. X            case TERM_HPX:    /* X11 HEWLETT-PACKARD */
  1431. X                delim = '-';
  1432. X                break;
  1433. X    
  1434. X            default:    /* everything else */
  1435. X                delim = DEFDELIMCH;
  1436. X                break;
  1437. X        }
  1438. X    }
  1439. X    else
  1440. X    {
  1441. X        delim = DEFDELIMCH;
  1442. X    }
  1443. X        
  1444. X    while(i--)
  1445. X        waddch(window, delim);
  1446. X
  1447. X    if(enter_alt_charset_mode && exit_alt_charset_mode && !opt_delimiter &&
  1448. X       *enter_alt_charset_mode && *exit_alt_charset_mode)
  1449. X    {
  1450. X        wattroff(window, A_ALTCHARSET);
  1451. X    }
  1452. X}    
  1453. X
  1454. X/*---------------------------------------------------------------------------*
  1455. X *    print error string in header-line
  1456. X *---------------------------------------------------------------------------*/
  1457. Xvoid error(char *str)
  1458. X{
  1459. X    extern int errno;
  1460. X    extern char *sys_errlist[];
  1461. X    extern int sys_nerr;
  1462. X
  1463. X    int i;
  1464. X
  1465. X    if(str == NULL)
  1466. X    {
  1467. X        if(errno && (errno <= sys_nerr))
  1468. X            strcpy(errorline, sys_errlist[errno]);
  1469. X        else
  1470. X            strcpy(errorline, "Unknown Error, call your guru ...");
  1471. X    }
  1472. X    strcpy(errorline, str);        
  1473. X
  1474. X    i = strlen(errorline);
  1475. X    while(i++ < COLS)
  1476. X        strcat(errorline," ");
  1477. X
  1478. X    wmove(cmnd_w, C_HEAD, 0);
  1479. X    wattron(cmnd_w, A_REVERSE);
  1480. X    waddstr(cmnd_w, errorline);
  1481. X    wattroff(cmnd_w, A_REVERSE);
  1482. X    wmove(cmnd_w, C_LINE, curcol());
  1483. X    suspend_time();
  1484. X    errorflag = 1;
  1485. X}
  1486. X
  1487. X/*---------------------------------------------------------------------------*
  1488. X *    clear error string and rewrite "normal" header
  1489. X *---------------------------------------------------------------------------*/
  1490. Xvoid clrerror(void)
  1491. X{
  1492. X    if(errorflag)                /* error-string in header ? */
  1493. X    {
  1494. X        resume_time();
  1495. X        errorflag = 0;            /* reset error-flag */        
  1496. X        wmove(cmnd_w, C_HEAD, 0);    /* headerline pos */
  1497. X        wclrtoeol(cmnd_w);        /* clear old */
  1498. X        header();            /* rewrite header */
  1499. X        wmove(cmnd_w, C_LINE, curcol());
  1500. X    }
  1501. X}    
  1502. X
  1503. X/*---------------------------------------------------------------------------*
  1504. X *    fatal, irrecoverable error
  1505. X *---------------------------------------------------------------------------*/
  1506. Xvoid fatal(char *str)
  1507. X{
  1508. X    free_list();        /* free memory */
  1509. X    fini_flabels();        /* fk-labels to normal */
  1510. X    endwin();        /* exit curses */
  1511. X    fprintf(stderr,"\n\n\t *** cwish Fatal Error: ***\n\t *** [%s] ***\n\n",str);
  1512. X    exit(1);
  1513. X}
  1514. X
  1515. X/*---------------------------------------------------------------------------*
  1516. X *    print headerline centered in display
  1517. X *---------------------------------------------------------------------------*/
  1518. Xvoid header(void)
  1519. X{
  1520. X    int p,q;
  1521. X
  1522. X    wmove(cmnd_w, C_HEAD, 0);
  1523. X
  1524. X    if(errorflag)
  1525. X    {
  1526. X        wattron(cmnd_w, A_REVERSE);
  1527. X        waddstr(cmnd_w, errorline);
  1528. X        wattroff(cmnd_w, A_REVERSE);
  1529. X    }
  1530. X    else
  1531. X    {
  1532. X        wattron(cmnd_w, A_REVERSE);
  1533. X        if((COLS+1) > 80)
  1534. X        {
  1535. X            p = (COLS+1) - 80;
  1536. X            p /= 2;
  1537. X            q = p;
  1538. X            while(q--)
  1539. X                waddch(cmnd_w, SPACE);
  1540. X            waddstr(cmnd_w, headerline);
  1541. X            q = p;
  1542. X            while(q--)
  1543. X            waddch(cmnd_w, SPACE);
  1544. X        }
  1545. X        else
  1546. X        {
  1547. X            waddstr(cmnd_w, headerline);
  1548. X        }
  1549. X        wattroff(cmnd_w, A_REVERSE);
  1550. X    }
  1551. X    sepaline(cmnd_w);
  1552. X    wmove(cmnd_w, C_LINE, curcol());
  1553. X}
  1554. X
  1555. X/*---------------------------------------------------------------------------*
  1556. X *    display the attribute window, init if required
  1557. X *---------------------------------------------------------------------------*/
  1558. Xvoid attribs(int flag)
  1559. X{
  1560. X    if(!opt_attrib)
  1561. X        return;
  1562. X        
  1563. X    if(flag)    /* rewrite static data ?? */
  1564. X    {
  1565. X        sepaline(attr_w);        /* draw horiz line */
  1566. X        wmove(attr_w, 1, 0);        /* start of line */
  1567. X        wclrtoeol(attr_w);        /* clear old */
  1568. X        
  1569. X        if(opt_altattr == 0)        /* normal */
  1570. X        {
  1571. X            wmove(attr_w, 1, PS_SIZE);
  1572. X            wattron(attr_w, A_REVERSE);
  1573. X            waddstr(attr_w, ST_SIZE);
  1574. X            wattroff(attr_w, A_REVERSE);
  1575. X    
  1576. X            wmove(attr_w, 1, PS_USER);
  1577. X            wattron(attr_w, A_REVERSE);
  1578. X            waddstr(attr_w, ST_USER);
  1579. X            wattroff(attr_w, A_REVERSE);
  1580. X            
  1581. X            wmove(attr_w, 1, PS_GRUP);
  1582. X            wattron(attr_w, A_REVERSE);
  1583. X            waddstr(attr_w, ST_GRUP);
  1584. X            wattroff(attr_w, A_REVERSE);
  1585. X    
  1586. X            wmove(attr_w, 1, PS_LINK);
  1587. X            wattron(attr_w, A_REVERSE);
  1588. X            waddstr(attr_w, ST_LINK);
  1589. X            wattroff(attr_w, A_REVERSE);
  1590. X        }
  1591. X        else    /* alternate */
  1592. X        {
  1593. X            wmove(attr_w, 1, APS_ADATE);
  1594. X            wattron(attr_w, A_REVERSE);
  1595. X            waddstr(attr_w, AST_ADATE);
  1596. X            wattroff(attr_w, A_REVERSE);
  1597. X            
  1598. X            wmove(attr_w, 1, APS_MDATE);
  1599. X            wattron(attr_w, A_REVERSE);
  1600. X            waddstr(attr_w, AST_MDATE);
  1601. X            wattroff(attr_w, A_REVERSE);
  1602. X            
  1603. X            wmove(attr_w, 1, APS_CDATE);
  1604. X            wattron(attr_w, A_REVERSE);
  1605. X            waddstr(attr_w, AST_CDATE);
  1606. X            wattroff(attr_w, A_REVERSE);
  1607. X
  1608. X            wmove(attr_w, 1, APS_INODE);
  1609. X            wattron(attr_w, A_REVERSE);
  1610. X            waddstr(attr_w, AST_INODE);
  1611. X            wattroff(attr_w, A_REVERSE);
  1612. X        }
  1613. X    }
  1614. X    if(opt_altattr == 0)    /* normal */
  1615. X    {
  1616. X        mvwaddstr(attr_w, 1, PP_PERM, cur_file->oprm);              /* permissions */
  1617. X        if(cur_file->oslink)                          /* a soft link ?? */
  1618. X            mvwaddch(attr_w, 1, PP_PERM, 'l');              /*     yes ! */
  1619. X        mvwaddstr(attr_w, 1, PP_DATE, cur_file->odat);                    /* date */
  1620. X        mvwprintw(attr_w, 1, PP_SIZE, "%-9d",cur_file->osiz);          /* filesize */
  1621. X        mvwaddstr(attr_w, 1, PP_USER, user_from_uid(cur_file->ousr, 8));  /* user */
  1622. X        mvwaddstr(attr_w, 1, PP_GRUP, group_from_gid(cur_file->ogrp, 8)); /* group */
  1623. X        mvwprintw(attr_w, 1, PP_LINK, "%-2d", cur_file->olinks);          /* hard links */
  1624. X    }
  1625. X    else    /* alternate */
  1626. X    {
  1627. X        register struct tm *tp;
  1628. X        static char buffer[16];
  1629. X
  1630. X        tp = localtime(&(cur_file->oatime));
  1631. X
  1632. X#ifdef DATE_US
  1633. X        sprintf(buffer,"%02d/%02d/%02d %02d:%02d",
  1634. X            (tp->tm_mon)+1,tp->tm_mday,tp->tm_year,
  1635. X            tp->tm_hour,tp->tm_min);
  1636. X#else
  1637. X        sprintf(buffer,"%02d.%02d.%02d %02d:%02d",
  1638. X            tp->tm_mday,(tp->tm_mon)+1,tp->tm_year,
  1639. X            tp->tm_hour,tp->tm_min);
  1640. X#endif /* DATE_US  */
  1641. X
  1642. X        mvwaddstr(attr_w, 1, APP_ADATE, buffer);        /* access date */
  1643. X
  1644. X        mvwaddstr(attr_w, 1, APP_MDATE, cur_file->odat);    /* modify date */
  1645. X
  1646. X        tp = localtime(&(cur_file->octime));
  1647. X
  1648. X#ifdef DATE_US
  1649. X        sprintf(buffer,"%02d/%02d/%02d %02d:%02d",
  1650. X            (tp->tm_mon)+1,tp->tm_mday,tp->tm_year,
  1651. X            tp->tm_hour,tp->tm_min);
  1652. X#else
  1653. X        sprintf(buffer,"%02d.%02d.%02d %02d:%02d",
  1654. X            tp->tm_mday,(tp->tm_mon)+1,tp->tm_year,
  1655. X            tp->tm_hour,tp->tm_min);
  1656. X#endif /* DATE_US */
  1657. X
  1658. X        mvwaddstr(attr_w, 1, APP_CDATE, buffer);        /* stat change date */
  1659. X
  1660. X        mvwprintw(attr_w, 1, APP_INODE, "%-10d", cur_file->oinode); /* inode */
  1661. X    }
  1662. X}
  1663. X
  1664. X/*---------------------------------- EOF -------------------------------------*/
  1665. X
  1666. END_OF_FILE
  1667.   if test 8632 -ne `wc -c <'header.c'`; then
  1668.     echo shar: \"'header.c'\" unpacked with wrong size!
  1669.   fi
  1670.   # end of 'header.c'
  1671. fi
  1672. if test -f 'history.c' -a "${1}" != "-c" ; then 
  1673.   echo shar: Will not clobber existing file \"'history.c'\"
  1674. else
  1675.   echo shar: Extracting \"'history.c'\" \(14580 characters\)
  1676.   sed "s/^X//" >'history.c' <<'END_OF_FILE'
  1677. X/*---------------------------------------------------------------------------*
  1678. X *
  1679. X *                  cwish - windowing user friendly shell
  1680. X *                  -------------------------------------
  1681. X *
  1682. X *               Copyright (c) 1988-1993 Hellmuth Michaelis
  1683. X *
  1684. X *                  Eggerstedtstr. 28
  1685. X *                  22765 Hamburg
  1686. X *                  Germany
  1687. X *
  1688. X *                  Tel:    +49 / 40 / 384298    (private)
  1689. X *                  Tel:    +49 / 40 / 55903-170 (at work)
  1690. X *                  e-mail: hm@hcshh.hcs.de
  1691. X *
  1692. X *                          --------oOo--------
  1693. X *
  1694. X *   This program is free software; you can redistribute it and/or modify
  1695. X *   it under the terms of the GNU General Public License as published by
  1696. X *   the Free Software Foundation; either version 2 of the License, or
  1697. X *   (at your option) any later version.
  1698. X *
  1699. X *   This program is distributed in the hope that it will be useful,
  1700. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1701. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1702. X *   GNU General Public License for more details.
  1703. X *
  1704. X *   You should have received a copy of the GNU General Public License
  1705. X *   along with this program; if not, write to the Free Software
  1706. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1707. X *
  1708. X *---------------------------------------------------------------------------*
  1709. X *
  1710. X *    last edit-date: [Fri Oct 29 13:14:49 1993]
  1711. X *
  1712. X *    -hm    history on commandline
  1713. X *    -hm    integrating line handling from terminal.c from my sh
  1714. X *    -hm    debugging line editor
  1715. X *
  1716. X *---------------------------------------------------------------------------*/ 
  1717. X
  1718. X#include "cwish.h"        /* local includes */
  1719. X
  1720. Xstatic char overstrike;        /* overstrike mode */
  1721. Xstatic char kbuf[HISLNLEN];    /* kill buffer */
  1722. Xstatic int  kbuf_init = 0;    /* static kill buffer */
  1723. Xstatic char *beg;        /* line start      (first char on line)    */
  1724. Xstatic char *pnt;        /* next insertion position     (cursor)    */
  1725. Xstatic char *end;        /* line end    (first free pos on line)    */
  1726. Xstatic char *sbeg;        /* first character on screen        */
  1727. Xstatic int lmax;        /* maximum charcount requested from caller */
  1728. X
  1729. Xstatic void pmstr(char *);        /* forward decl */
  1730. Xstatic void pnstr(int, char *);
  1731. Xvoid dis_hist(void);
  1732. X
  1733. X/*---------------------------------------------------------------------------*
  1734. X *    return current (cursor) column
  1735. X *---------------------------------------------------------------------------*/
  1736. Xint curcol(void)
  1737. X{
  1738. X    return((int)(pnt - sbeg));
  1739. X}
  1740. X
  1741. X/*---------------------------------------------------------------------------*
  1742. X *    return true, if commandline empty ( == operate on file window on CR )
  1743. X *---------------------------------------------------------------------------*/
  1744. Xint cr_on_files(void)
  1745. X{
  1746. X    return((int)(beg == end));
  1747. X}
  1748. X
  1749. X/*---------------------------------------------------------------------------*
  1750. X *    init commandline history system
  1751. X *---------------------------------------------------------------------------*/
  1752. Xvoid init_history(void)
  1753. X{
  1754. X    overstrike = 0;        /* insert is default */
  1755. X    
  1756. X    cur_his = 0;        /* current history pointer */
  1757. X    strcpy(cbuff,hislines[cur_his]);
  1758. X
  1759. X    sbeg = cbuff;        /* screen begin at start of buffer */
  1760. X    beg = cbuff + strlen(cbuff);    /* position beg after prompt */
  1761. X    pnt = end = beg;    /* point = end = buffer begin */
  1762. X
  1763. X    kbuf[0] = '\0';        /* init kill - buffer */
  1764. X    kbuf_init = 1;        /* static kbuf */
  1765. X    
  1766. X    lmax = HISLNLEN-1;    /* max line length */
  1767. X
  1768. X    wmove(cmnd_w,C_LINE,0);    /* beg of line */
  1769. X    waddstr(cmnd_w, cbuff);    /* write prompt */
  1770. X}    
  1771. X
  1772. X/*---------------------------------------------------------------------------*
  1773. X *    save current commandline to history stack
  1774. X *---------------------------------------------------------------------------*/
  1775. Xvoid save_line(void)
  1776. X{
  1777. X    strncpy(hislines[cur_his],cbuff,HISLNLEN-1);
  1778. X    if(cur_his == HISLINES-1)
  1779. X        cur_his = 0;
  1780. X    else
  1781. X        cur_his++;
  1782. X    hislines[cur_his][3] = '\0';    
  1783. X    dis_hist();
  1784. X}    
  1785. X
  1786. X/*---------------------------------------------------------------------------*
  1787. X *    get previous history line
  1788. X *---------------------------------------------------------------------------*/
  1789. Xvoid prev_line(void)
  1790. X{
  1791. X    if(cur_his == 0)
  1792. X        cur_his = HISLINES-1;
  1793. X    else
  1794. X        cur_his--;
  1795. X
  1796. X    dis_hist();
  1797. X}
  1798. X
  1799. X/*---------------------------------------------------------------------------*
  1800. X *    get next history line
  1801. X *---------------------------------------------------------------------------*/
  1802. Xvoid next_line(void)
  1803. X{
  1804. X    if(cur_his == HISLINES-1)
  1805. X        cur_his = 0;
  1806. X    else
  1807. X        cur_his++;
  1808. X
  1809. X    dis_hist();
  1810. X}
  1811. X
  1812. X/*---------------------------------------------------------------------------*
  1813. X *    valid new line from history stack, display it
  1814. X *---------------------------------------------------------------------------*/
  1815. Xvoid dis_hist(void)
  1816. X{
  1817. X    strncpy(cbuff,hislines[cur_his],HISLNLEN-1);
  1818. X    
  1819. X    if((strlen(cbuff)) < COLS)
  1820. X    {                 /* new line will fit onto screen */
  1821. X        wmove(cmnd_w,C_LINE,0);    /* move to start of line */
  1822. X        wclrtoeol(cmnd_w);    /* clear line */
  1823. X        wmove(cmnd_w,C_LINE,0);    /* move to start of line */
  1824. X        waddstr(cmnd_w, cbuff);    /* write new line */
  1825. X        sbeg = cbuff;        /* new screen begin */
  1826. X    }
  1827. X    else
  1828. X    { /* line will not fit onto screen, search end & write new */
  1829. X        wmove(cmnd_w,C_LINE,0);        /* start of line */
  1830. X        wclrtoeol(cmnd_w);        /* clear to end of line */
  1831. X        sbeg = cbuff;            /* start of buffer */
  1832. X        while((strlen(sbeg) + 1) > COLS) /* find segment */
  1833. X            sbeg += COLS/2;        /*             start */
  1834. X        waddstr(cmnd_w, sbeg);        /* write last segment */
  1835. X    }
  1836. X    pnt = end = (cbuff + strlen(cbuff));
  1837. X    beg = cbuff + 3;    /* position beg after prompt */    
  1838. X}
  1839. X
  1840. X/*---------------------------------------------------------------------------*
  1841. X *        move cursor forward
  1842. X *---------------------------------------------------------------------------*/
  1843. Xvoid right_line(void)
  1844. X{
  1845. X    if(pnt < end)        /* something to move ? */
  1846. X    {
  1847. X        pnt++;        /* next char */
  1848. X        if(pnt > (sbeg + COLS))    /* moving on screen ? */
  1849. X        {
  1850. X            sbeg += COLS/2;    /* new screen begin */
  1851. X            wmove(cmnd_w,C_LINE,0);    /* start of screen */
  1852. X            wclrtoeol(cmnd_w);    /* clear line */
  1853. X            pmstr(sbeg);        /* write new segment */
  1854. X        }
  1855. X    }
  1856. X}
  1857. X
  1858. X/*---------------------------------------------------------------------------*
  1859. X *        move cursor back one character
  1860. X *---------------------------------------------------------------------------*/
  1861. Xvoid left_line(void)
  1862. X{
  1863. X    if(pnt > beg)    /* allowed to move ?? */
  1864. X    {
  1865. X        pnt--;            /* prev char */
  1866. X        if(pnt < sbeg)        /* move on screen ?? */
  1867. X        {
  1868. X            sbeg -= COLS/2;    /* back 1/2 length */
  1869. X            wmove(cmnd_w,C_LINE,0);    /* start of screen */
  1870. X            wclrtoeol(cmnd_w);    /* clear line */
  1871. X            pmstr(sbeg);        /* print this part of buffer */
  1872. X        }
  1873. X    }
  1874. X}
  1875. X
  1876. X/*---------------------------------------------------------------------------*
  1877. X *    append / insert / overstrike a (printable) character
  1878. X *---------------------------------------------------------------------------*/
  1879. Xint cmdline(int c)
  1880. X{
  1881. X    if((end-beg) < lmax)    /* space in buffer ? */
  1882. X    {
  1883. X        if(pnt == end)    /************ append **********/
  1884. X        {
  1885. X            *pnt++ = c;        /* store char */
  1886. X            end++;            /* new end ptr */
  1887. X            *end = '\0';        /* new terminator */
  1888. X
  1889. X            if((end-sbeg+1) > COLS)
  1890. X            {
  1891. X                sbeg += COLS/2;
  1892. X                wmove(cmnd_w,C_LINE,0);
  1893. X                wclrtoeol(cmnd_w);
  1894. X                waddstr(cmnd_w, sbeg);
  1895. X            }
  1896. X            else
  1897. X            {
  1898. X                waddch(cmnd_w,c);    /* echo char */
  1899. X            }
  1900. X        }
  1901. X        else if(!overstrike)    /************** insert **********/
  1902. X        {
  1903. X            register char *p;
  1904. X            register char *q;
  1905. X
  1906. X            p = end-1;        /* last char */
  1907. X            q = end;        /* last char + 1 */
  1908. X            while(q > pnt)        /* shift right buffer */
  1909. X                *q-- = *p--;
  1910. X
  1911. X            *pnt = c;        /* store chr into gap */
  1912. X            end++;            /* increment end ptr */
  1913. X            *end = '\0';        /* new terminator */
  1914. X            
  1915. X            if( (pnt+1) > (sbeg + COLS)) /* scroll right ? */
  1916. X            {
  1917. X                sbeg += COLS/2;    /* new screen beg */
  1918. X            }
  1919. X            wmove(cmnd_w,C_LINE,0);    /* start of line */
  1920. X            pmstr(sbeg);        /* print string */
  1921. X            pnt++;            /* new point */
  1922. X        }
  1923. X        else        /**************    overstrike ****************/
  1924. X        {
  1925. X            *pnt++ = c;        /* store char */
  1926. X
  1927. X            if((pnt-sbeg+1) > COLS)
  1928. X            {
  1929. X                sbeg += COLS/2;
  1930. X                wmove(cmnd_w,C_LINE,0);
  1931. X                wclrtoeol(cmnd_w);
  1932. X                pmstr(sbeg);
  1933. X            }
  1934. X            else
  1935. X            {
  1936. X                waddch(cmnd_w,c);    /* echo char */
  1937. X            }
  1938. X        }
  1939. X        return(GOOD);
  1940. X    }
  1941. X    else
  1942. X    {
  1943. X        flash();    /* no no .. */
  1944. X        return(BAD);    /* don't accept it */
  1945. X    }
  1946. X}
  1947. X
  1948. X/*---------------------------------------------------------------------------*
  1949. X *        delete character left of cursor
  1950. X *---------------------------------------------------------------------------*/
  1951. Xvoid handlebs(void)
  1952. X{
  1953. X    register char *p;
  1954. X    register char *q;
  1955. X
  1956. X    if(pnt == beg)        /* at start of buffer ? */
  1957. X        return;        /* yes */
  1958. X
  1959. X    q = pnt;        /* next char */
  1960. X    pnt--;            /* point backward */
  1961. X    p = pnt;        /* this char */
  1962. X    while(q < end)        /* shift left buffer */
  1963. X        *p++ = *q++;
  1964. X    end--;            /* new end pointer */
  1965. X    *end = '\0';        /* new end terminator */
  1966. X
  1967. X    if(pnt < sbeg)            /* moved into previous segment ? */
  1968. X    {
  1969. X        sbeg -= COLS/2;        /* new segment start */
  1970. X    }
  1971. X    wmove(cmnd_w,C_LINE,0);    /* start of screen line */
  1972. X    wclrtoeol(cmnd_w);    /* clear line */
  1973. X    pmstr(sbeg);        /* write segment */
  1974. X}
  1975. X
  1976. X/*---------------------------------------------------------------------------*
  1977. X *        delete character under cursor
  1978. X *---------------------------------------------------------------------------*/
  1979. Xvoid del_char(void)
  1980. X{
  1981. X    register char *p;
  1982. X    register char *q;
  1983. X
  1984. X    if(pnt == end)        /* at start of buffer ? */
  1985. X        return;        /* yes */
  1986. X
  1987. X    p = pnt;        /* current char */
  1988. X    q = pnt+1;        /* next char */
  1989. X
  1990. X    while(q < end)        /* shift left buffer */
  1991. X        *p++ = *q++;
  1992. X
  1993. X    end--;            /* new end pointer */
  1994. X    *end = '\0';        /* new end terminator */
  1995. X
  1996. X    wmove(cmnd_w,C_LINE,0);    /* start of screen line */
  1997. X    wclrtoeol(cmnd_w);    /* clear line */
  1998. X    pmstr(sbeg);        /* write new segment */
  1999. X}
  2000. X
  2001. X/*---------------------------------------------------------------------------*
  2002. X *        print string, maximum length is COLS
  2003. X *---------------------------------------------------------------------------*/
  2004. Xstatic void pmstr(char *str)
  2005. X{
  2006. X    char buf[256];
  2007. X    register int i = 0;
  2008. X    
  2009. X    while((*str) && (i < COLS))
  2010. X        buf[i++] = *str++;
  2011. X    buf[i] = '\0';
  2012. X    waddstr(cmnd_w, buf);
  2013. X}
  2014. X
  2015. X/*---------------------------------------------------------------------------*
  2016. X *        print string, maximum length parameter <n>
  2017. X *---------------------------------------------------------------------------*/
  2018. Xstatic void pnstr(int n, char *str)
  2019. X{
  2020. X    char buf[256];
  2021. X    register int i = 0;
  2022. X    
  2023. X    while((*str) && (i < n))
  2024. X        buf[i++] = *str++;
  2025. X    buf[i] = '\0';
  2026. X    waddstr(cmnd_w, buf);
  2027. X}
  2028. X
  2029. X/*---------------------------------------------------------------------------*
  2030. X *         delete from cursor to end of line
  2031. X *---------------------------------------------------------------------------*/
  2032. Xvoid clear_toeol(void)
  2033. X{
  2034. X    strcpy(kbuf, pnt);    /* save to kill buffer */
  2035. X    wclrtoeol(cmnd_w);    /* clear line */
  2036. X    end = pnt;        /* new end ptr */
  2037. X    *end = '\0';        /* terminate line */
  2038. X}
  2039. X
  2040. X/*---------------------------------------------------------------------------*
  2041. X *        move cursor to end of line
  2042. X *---------------------------------------------------------------------------*/
  2043. Xvoid eol_line(void)
  2044. X{
  2045. X    if(pnt == end)        /* already at end ? */
  2046. X        return;        /* yes */
  2047. X
  2048. X    if((strlen(cbuff) < COLS) && (sbeg == cbuff))
  2049. X    {
  2050. X        pnt = end;    /* set point to end */
  2051. X    }        
  2052. X    else
  2053. X    {
  2054. X        wmove(cmnd_w,C_LINE,0);    /* start of line */
  2055. X        wclrtoeol(cmnd_w);    /* clear to end of line */
  2056. X        sbeg = cbuff;        /* start of buffer */
  2057. X        while((strlen(sbeg) + 1) > COLS) /* find segment */
  2058. X            sbeg += COLS/2;        /*             start */
  2059. X        waddstr(cmnd_w, sbeg);    /* write last segment */
  2060. X        pnt = end;        /* new point */
  2061. X    }
  2062. X}    
  2063. X
  2064. X/*---------------------------------------------------------------------------*
  2065. X *         move cursor to begin of line
  2066. X *---------------------------------------------------------------------------*/
  2067. Xvoid bol_line(void)
  2068. X{
  2069. X    if(pnt == beg)            /* already at begin of buffer */
  2070. X        return;            /* nothing to do ! */
  2071. X
  2072. X    pnt = beg;            /* point = buffer start */
  2073. X    
  2074. X    if(sbeg != cbuff)        /* not in first screen segment */
  2075. X    {
  2076. X        wmove(cmnd_w,C_LINE,0);    /* cursor -> start of screen */
  2077. X        wclrtoeol(cmnd_w);    /* clear to end of line */
  2078. X        pmstr(cbuff);        /* write from start of buffer */
  2079. X        sbeg = cbuff;        /* screen begin = buffer start */
  2080. X    }
  2081. X}
  2082. X
  2083. X/*---------------------------------------------------------------------------*
  2084. X *        yank text from kill-buffer to current point
  2085. X *---------------------------------------------------------------------------*/
  2086. Xvoid yank(void)
  2087. X{
  2088. X    if(kbuf[0] == '\0')    /* kill buffer empty ? */
  2089. X        return;        /* yes, exit */
  2090. X
  2091. X    if((end - beg) >= lmax)             /* space in buffer ? */
  2092. X    {                     /* no... */
  2093. X        if((overstrike) && (pnt == end)) /* perhaps overstr in the middle ? */
  2094. X            return;             /* no... */
  2095. X        if(!overstrike)             /* insert / append ? */
  2096. X            return;             /* yes */
  2097. X    }
  2098. X
  2099. X    /* here if either space in buffer or overwrite not at end */
  2100. X        
  2101. X    if(pnt == end)        /************ append **********/
  2102. X    {
  2103. X        /* append kill buffer to buffer, observe buffer max length */
  2104. X        
  2105. X        strncat(cbuff, kbuf, lmax);
  2106. X        end = cbuff + strlen(cbuff);
  2107. X        if((end-sbeg+1) > COLS)
  2108. X        {
  2109. X            while((end-sbeg+1) > COLS)
  2110. X                sbeg += COLS/2;
  2111. X            wmove(cmnd_w,C_LINE,0);
  2112. X            wclrtoeol(cmnd_w);
  2113. X            waddstr(cmnd_w, sbeg);    /* write whole new segment */
  2114. X        }
  2115. X        else
  2116. X        {
  2117. X            waddstr(cmnd_w, pnt);    /* write new end */
  2118. X        }
  2119. X        pnt = end;        /* set new pnt */
  2120. X    }
  2121. X    else if(!overstrike)    /************** insert **********/
  2122. X    {
  2123. X        char tail[HISLNLEN];    /* temp storage */
  2124. X        register int i;        /* gp... */
  2125. X        register char *p = pnt;    /* save point pos */
  2126. X        
  2127. X        strcpy(tail, pnt);    /* save string frm point on */
  2128. X        strncpy(pnt, kbuf, lmax); /* insert up to max */
  2129. X        pnt = cbuff + strlen(cbuff);
  2130. X        strcat(pnt, tail);    /* append saved tail */
  2131. X        end = cbuff + strlen(cbuff);
  2132. X
  2133. X        if((pnt-sbeg+1) > COLS)
  2134. X        { /* new point is outside current segment */
  2135. X            while((pnt-sbeg+1) > COLS)
  2136. X                sbeg += COLS/2;
  2137. X            wmove(cmnd_w,C_LINE,0);
  2138. X            wclrtoeol(cmnd_w);
  2139. X            pmstr(sbeg);        /* print string */
  2140. X        }
  2141. X        else
  2142. X        { /* new point is inside current segment */
  2143. X            if((strlen(sbeg)) < COLS) /* line > than screen ? */
  2144. X                i = (sbeg + strlen(sbeg)) - p; /* no */
  2145. X            else
  2146. X                i = (sbeg + COLS) - p; /* yes */
  2147. X            pnstr(i, p);        /* new tail */
  2148. X            p += i;
  2149. X            while(p-- > pnt)
  2150. X                wmove(cmnd_w, C_LINE, (curcol()-1));
  2151. X        }
  2152. X    }
  2153. X    else        /**************    overstrike ****************/
  2154. X    {
  2155. X        register int j = lmax;
  2156. X        register char *k = kbuf;
  2157. X        
  2158. X        while(j-- && *k)
  2159. X            *pnt++ = *k++;    /* copy kbuf over buffer */
  2160. X        
  2161. X        if(pnt > end)    /* buffer grown bigger ? */
  2162. X        {
  2163. X            end = pnt;    /* set new end ptr */
  2164. X            *end = '\0';    /* terminate buffer */
  2165. X        }
  2166. X
  2167. X        if((pnt-sbeg+1) > COLS)
  2168. X        { /* new point is outside current segment */
  2169. X            while((pnt-sbeg+1) > COLS)
  2170. X                sbeg += COLS/2;
  2171. X            wmove(cmnd_w,C_LINE,0);
  2172. X            wclrtoeol(cmnd_w);
  2173. X            pmstr(sbeg);        /* print string */
  2174. X        }
  2175. X        else
  2176. X        { /* new point is inside current segment */
  2177. X            waddstr(cmnd_w, kbuf);
  2178. X        }
  2179. X    }
  2180. X}
  2181. X
  2182. X/*----------------------- E O F -------------------------------------------*/
  2183. END_OF_FILE
  2184.   if test 14580 -ne `wc -c <'history.c'`; then
  2185.     echo shar: \"'history.c'\" unpacked with wrong size!
  2186.   fi
  2187.   # end of 'history.c'
  2188. fi
  2189. echo shar: End of archive 3 \(of 5\).
  2190. cp /dev/null ark3isdone
  2191. MISSING=""
  2192. for I in 1 2 3 4 5 ; do
  2193.     if test ! -f ark${I}isdone ; then
  2194.     MISSING="${MISSING} ${I}"
  2195.     fi
  2196. done
  2197. if test "${MISSING}" = "" ; then
  2198.     echo You have unpacked all 5 archives.
  2199.     rm -f ark[1-9]isdone
  2200. else
  2201.     echo You still must unpack the following archives:
  2202.     echo "        " ${MISSING}
  2203. fi
  2204. exit 0
  2205. exit 0 # Just in case...
  2206.