[comp.sources.misc] v20i003: scan - A directory menu program, Part03/03

pat@kai.com (Patrick J. Wolfe) (05/21/91)

Submitted-by: Patrick J. Wolfe <pat@kai.com>
Posting-number: Volume 20, Issue 3
Archive-name: scan/part03

#! /bin/sh
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# Contents:  Makefile Todo funcmenu.c getch.c getch.h main.c readrc.h
#   runcmd.c scan.1 setupmenu.c
# Wrapped by kent@sparky on Tue May 21 00:34:20 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
echo If this archive is complete, you will see the following message:
echo '          "shar: End of archive 3 (of 3)."'
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
  echo shar: Extracting \"'Makefile'\" \(2974 characters\)
  sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#	Scan directory menu program
X#	edit config.h to make sure your system type and signal values are okay
X#
X
X#	for SGI Irix 3.3
X#LIBS = -lsun -lcurses
X
X#	for BSD 4.2 (Dynix 3, Concentrix 5.5)
XLIBS = -lcurses -ltermcap
X
X#	for Esix (AT&T Unix) System V/386 Release 3.2
X#CC = gcc -traditional
X#LIBS = -lcurses -lbsd -lc_s
X
X#	for HP/UX 7.0 or later
X#LIBS = -lcurses -lBSD
X
XCFLAGS = -O
XLDFLAGS = $(CFLAGS)
XLINTFLAGS = -vx -DLINT
X
X# where to install things
XPGM = scan
XBIN = /usr/local/bin
XMANSECT = l
XMANPAGE = /usr/man/man$(MANSECT)/scan.$(MANSECT)
X
XSHELL = /bin/sh
XOBJS = filemenu.o fileops.o funcmenu.o getch.o keymenu.o main.o optionmenu.o readrc.o runcmd.o setupmenu.o userfuncs.o
XSRCS = filemenu.c fileops.c funcmenu.c getch.c keymenu.c main.c optionmenu.c readrc.c runcmd.c setupmenu.c userfuncs.c
X
XFILES1 = README scan.1 Makefile Todo config.h defkeys.h getch.h readrc.h userfuncs.c
XFILES2 = filemenu.c fileops.c funcmenu.c getch.c keymenu.c main.c optionmenu.c readrc.c runcmd.c setupmenu.c
X
Xscan:$& $(OBJS)
X	rm -f scan.new
X	$(CC) -o scan.new $(LDFLAGS) $(OBJS) $(LIBS)
X	rm -f scan.old
X	test ! -f scan || mv scan scan.old
X	mv scan.new scan
X
Xinstall: scan
X	rm -f $(BIN)/$(PGM)
X	cp scan $(BIN)/$(PGM)
X	strip $(BIN)/$(PGM)
X	chmod 755 $(BIN)/$(PGM)
X	ls -l $(BIN)/$(PGM)
X
Xmanpage: scan.1
X	rm -f $(MANPAGE)
X	cp scan.1 $(MANPAGE)
X	chmod 644 $(MANPAGE)
X	ls -l $(MANPAGE)
X
Xlint:
X	lint $(LINTFLAGS) $(SRCS)
X
Xclean:
X	rm -f a.out core mklog scan scan.old scan.shar* *.o
X
Xshar: $(FILES1) $(FILES2)
X	shar $(FILES1) > scan.shar1
X	shar $(FILES2) > scan.shar2
X	ls -l scan.shar1 scan.shar2
X
Xfileops.o: config.h
Xfilemenu.o: config.h getch.h
Xfuncmenu.o: config.h getch.h
Xgetch.o: config.h getch.h
Xmain.o: config.h getch.h defkeys.h
Xkeymenu.o: config.h getch.h
Xoptionmenu.o: config.h getch.h
Xreadrc.o: config.h getch.h readrc.h
Xruncmd.o: config.h
Xsetupmenu.o: config.h getch.h
Xuserfuncs.o: config.h
X
X#
X# This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
X#
X# Permission is hereby granted to copy, distribute or otherwise 
X# use any part of this package as long as you do not try to make 
X# money from it or pretend that you wrote it.  This copyright 
X# notice must be maintained in any copy made.
X#
X# Use of this software constitutes acceptance for use in an AS IS 
X# condition. There are NO warranties with regard to this software.  
X# In no event shall the author be liable for any damages whatsoever 
X# arising out of or in connection with the use or performance of this 
X# software.  Any use of this software is at the user's own risk.
X#
X# If you make modifications to this software that you feel 
X# increases it usefulness for the rest of the community, please 
X# email the changes, enhancements, bug fixes as well as any and 
X# all ideas to me. This software is going to be maintained and 
X# enhanced as deemed necessary by the community.
X#              
X#              Patrick J. Wolfe
X#              uunet!uiucuxc!kailand!pwolfe
X#              pwolfe@kailand.kai.com
X#
END_OF_FILE
  if test 2974 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
  fi
  # end of 'Makefile'
fi
if test -f 'Todo' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Todo'\"
else
  echo shar: Extracting \"'Todo'\" \(1830 characters\)
  sed "s/^X//" >'Todo' <<'END_OF_FILE'
X*** FIX BUGS ***
X
X- there are currently none that I am aware of
X
X*** ENHANCE CURRENT FEATURES ***
X
X- handle SIGWINCH window size changes correctly.
X
X- update the manpage.  Double check the real default bindings, and add a
X  table of builtin functions.
X
X- need improved rm_tagged function which deletes files properly with "rm -f",
X  and directories with "rmdir", to prevent accidentally deleting all
X  subdirectories and their contents.
X
X- check if the directory itself has been updated (files added or deleted) and
X  display something to let the user know to "re-read current directory" (or
X  remember the current file and do it automatically).
X
X- the "help screen" function only describes the default key bindings, which
X  a user may change at any time.  It should describe the current bindings.
X  Maybe a table of descriptions for each function, and a scrollable menu
X  showing keys and their bindings.
X
X- find a way to get curses to use the "deleteln" and "insertln" routines
X  correctly, so the menu scrolls better.  SVR3 curses does, BSD doesn't.
X  Maybe on SVR3, allow down arrow to scroll the menu one line at a time,
X  which looks smoother than jumping a half of a screen at a time.
X
X
X*** ADD NEW FEATURES ***
X
X- A "File Operations Menu" would be nice.  This would have options to delete,
X  rename, copy, tar, etc... current or tagged files.  Also, create file and
X  subdirectory.
X
X- permissions menu, for assisting secretary types with modifying a file's
X  access permissions.
X
X- search function, for tagging files whose name matches some wildcard string
X  bind to "/".  Also, "n", "N", "?".
X
X- grep function, for tagging files which contain some wildcard string
X  bind to "g". "G" could untag files with match, or it could tag files
X  with DON'T match.  This could be confusing.  Maybe a submenu is called
X  for here.
X
END_OF_FILE
  if test 1830 -ne `wc -c <'Todo'`; then
    echo shar: \"'Todo'\" unpacked with wrong size!
  fi
  # end of 'Todo'
fi
if test -f 'funcmenu.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'funcmenu.c'\"
else
  echo shar: Extracting \"'funcmenu.c'\" \(4919 characters\)
  sed "s/^X//" >'funcmenu.c' <<'END_OF_FILE'
X
X/*
X * This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
X *
X * Permission is hereby granted to copy, distribute or otherwise 
X * use any part of this package as long as you do not try to make 
X * money from it or pretend that you wrote it.  This copyright 
X * notice must be maintained in any copy made.
X *
X * Use of this software constitutes acceptance for use in an AS IS 
X * condition. There are NO warranties with regard to this software.  
X * In no event shall the author be liable for any damages whatsoever 
X * arising out of or in connection with the use or performance of this 
X * software.  Any use of this software is at the user's own risk.
X *
X * If you make modifications to this software that you feel 
X * increases it usefulness for the rest of the community, please 
X * email the changes, enhancements, bug fixes as well as any and 
X * all ideas to me. This software is going to be maintained and 
X * enhanced as deemed necessary by the community.
X *              
X *              Patrick J. Wolfe
X *              uunet!uiucuxc!kailand!pwolfe
X *              pwolfe@kailand.kai.com
X */
X
X#include "config.h"
Xextern struct funcname_entry funcname_table[];
X
Xstatic void redraw_data();
Xstatic WINDOW *header_window, *data_window, *help_window;
Xstatic int top = 0, current = 0, last;
X
X
Xstatic
Xdown_one_line ()
X{
Xif (current < last) {
X	current++;
X	if (current > (top + 14)) {
X		top += 14;
X		if (top >= (last - 14)) {
X			top = last - 14;
X			if (top < 0) {
X				top = 0;
X				}
X			}
X		}
X	redraw_data ();
X	}
Xelse	{
X	beep();
X	}
X}
X
X
Xstatic
Xup_one_line ()
X{
Xif (current > 0) {
X	current--;
X	if (current < top) {
X		top -= 14;
X		if (top < 0) {
X			top = 0;
X			}
X		}
X	redraw_data ();
X	}
Xelse	{
X	beep();
X	}
X}
X
X
Xstatic
Xdown_one_screen ()
X{
Xif (top < (last - 14)) {
X	top += 15;
X	if (top >= (last - 14)) {
X		top = last - 14;
X		if (top < 0) {
X			top = 0;
X			}
X		}
X	current = top;
X	redraw_data ();
X	}
Xelse if (current < last) {
X	current = last;
X	redraw_data ();
X	}
Xelse	{
X	beep();
X	}
X}
X
X
Xstatic
Xup_one_screen ()
X{
Xif (top > 0) {
X	top -= 15;
X	if (top < 0) {
X		top = 0;
X		}
X	current = top + 14;
X	if (current > last) {
X		current = last;
X		}
X	redraw_data ();
X	}
Xelse if (current > 0) {
X	current = 0;
X	redraw_data ();
X	}
Xelse	{
X	beep();
X	}
X}
X
X
Xstatic void
Xredraw_data ()
X{
Xint row, ptr;
X
Xwmove (data_window, 0, 0);
Xwclrtobot (data_window);
Xfor (row = 0, ptr = top; (ptr <= last) && (row < 15); ptr++, row++) {
X	if (ptr == current) {
X		wstandout (data_window);
X		}
X	
X	mvwaddstr (data_window, row, 0, (char *) funcname_table[ptr].name);
X
X	if (ptr == current) {
X		wstandend (data_window);
X		}
X	}
Xwrefresh (data_window);
X}
X
X
Xstatic
Xredraw_all ()
X{
Xwmove (header_window, 0, 0);
Xwclrtobot (header_window);
Xwmove (header_window, 1, 10);
Xwstandout (header_window);
Xwaddstr (header_window, PGM_VERSION);
Xwaddstr (header_window, " Builtin Function Selection Menu");
Xwstandend (header_window);
Xwmove (header_window, 3, 3);
Xwaddstr (header_window, "function name");
Xwmove (header_window, 4, 0);
Xwaddstr (header_window, "-------------");
Xwrefresh (header_window);
X
Xredraw_data ();
X
Xwmove (help_window, 0, 0);
Xwclrtobot (help_window);
Xwmove (help_window, 0, 0);
Xwaddstr (help_window, "+----------------------------------------------------------------------------+");
Xwmove (help_window, 1, 0);
Xwaddstr (help_window, "|     use ^F, ^B, j, k and/or the arrow keys to move around the display      |");
Xwmove (help_window, 2, 0);
Xwaddstr (help_window, "|     Return selects the highlighted function, Q cancels the key definition  |");
Xwmove (help_window, 3, 0);
Xwaddstr (help_window, "+----------------------------------------------------------------------------+");
Xwrefresh (help_window);
X}
X
X
Xvoidptr
Xfunction_menu ()
X{
Xint c;
X
X/* find last function in table */
Xfor (last = 0; funcname_table[last].kfunc != NULL; last++);
X
Xheader_window = newwin (5, 80, 0, 0);
Xdata_window = newwin (15, 80, 5, 0);
Xhelp_window = newwin (4, 80, 20, 0);
X#ifdef SYSVcurses
Xidlok (data_window, TRUE);
X#endif
Xredraw_all ();
X
Xwhile (1) {
X	c = my_getch (header_window);
X	switch (c) {
X
X	case ControlB:
X	case KEY_PPAGE:
X	case KEY_PrevScreen:
X		up_one_screen ();
X		break;
X
X	case ControlF:
X	case KEY_NPAGE:
X	case KEY_NextScreen:
X		down_one_screen ();
X		break;
X
X	case 'k':
X	case KEY_UP:
X	case ControlP:
X		up_one_line ();
X		break;
X
X	case 'j':
X	case KEY_DOWN:
X	case ControlN:
X		down_one_line ();
X		break;
X	
X	case 'q':
X	case 'Q':
X	case ControlM:
X		wmove (header_window, 0, 0);
X		wclrtobot (header_window);
X		wrefresh (header_window);
X		delwin (header_window);
X		wmove (data_window, 0, 0);
X		wclrtobot (data_window);
X		wrefresh (data_window);
X		delwin (data_window);
X		wmove (help_window, 0, 0);
X		wclrtobot (help_window);
X		wrefresh (help_window);
X		delwin (help_window);
X		if (c == ControlM)
X			return ((voidptr) funcname_table[current].kfunc);
X		return ((voidptr) NULL);
X
X	case ControlL:
X	case ControlR:
X		redraw_all ();
X		break;
X
X	default:
X		beep();
X		}
X	}
X}
END_OF_FILE
  if test 4919 -ne `wc -c <'funcmenu.c'`; then
    echo shar: \"'funcmenu.c'\" unpacked with wrong size!
  fi
  # end of 'funcmenu.c'
fi
if test -f 'getch.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'getch.c'\"
else
  echo shar: Extracting \"'getch.c'\" \(3184 characters\)
  sed "s/^X//" >'getch.c' <<'END_OF_FILE'
X
X/*
X * This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
X *
X * Permission is hereby granted to copy, distribute or otherwise 
X * use any part of this package as long as you do not try to make 
X * money from it or pretend that you wrote it.  This copyright 
X * notice must be maintained in any copy made.
X *
X * Use of this software constitutes acceptance for use in an AS IS 
X * condition. There are NO warranties with regard to this software.  
X * In no event shall the author be liable for any damages whatsoever 
X * arising out of or in connection with the use or performance of this 
X * software.  Any use of this software is at the user's own risk.
X *
X * If you make modifications to this software that you feel 
X * increases it usefulness for the rest of the community, please 
X * email the changes, enhancements, bug fixes as well as any and 
X * all ideas to me. This software is going to be maintained and 
X * enhanced as deemed necessary by the community.
X *              
X *              Patrick J. Wolfe
X *              uunet!uiucuxc!kailand!pwolfe
X *              pwolfe@kailand.kai.com
X */
X
X#include "config.h"
X
X#define NORMAL	100
X#define ESCAPE	200
X#define FKEY	300
X
X
Xint
Xmy_getch (winptr)
XWINDOW *winptr;
X{
Xchar c;
Xint state = NORMAL;
Xint fkeycount = 0;
X
Xwhile (1) {
X	c = wgetch (winptr);	/* call the real getch() to return a single character */
X	switch (state) {
X
X	case FKEY:
X		switch (c) {
X
X		/* numeric function keys */
X		case '0': case '1': case '2': case '3': case '4':
X		case '5': case '6': case '7': case '8': case '9':
X			fkeycount = (fkeycount * 10) + (c - '0');
X			break;
X		
X		case '~':
X			switch (fkeycount) {
X
X			/* Find, Insert Here, Remove, Select, Prev Screen, Next Screen */
X			case 1: case 2: case 3: case 4: case 5: case 6:
X				return KEY_Find + (fkeycount - 1);
X
X			/* unshifted vt220 function keys */
X			case 17: case 18: case 19: case 20: case 21:
X			case 22: case 23: case 24: case 25: case 26:
X			case 27: case 28: case 29: case 30: case 31:
X				return KEY_F6 + (fkeycount - 17);
X
X			/* shifted tvs922 function keys */
X			case 37: case 38: case 39: case 40: case 41:
X			case 42: case 43: case 44: case 45: case 46:
X			case 47: case 48: case 49: case 50: case 51:
X				return KEY_SF6 + (fkeycount - 37);
X
X			default:
X				beep();
X				state = NORMAL;
X				}
X			break;
X
X		case 'A':	return KEY_UP;
X		case 'B':	return KEY_DOWN;
X		case 'C':	return KEY_RIGHT;
X		case 'D':	return KEY_LEFT;
X		case 'M':	return KEY_PadEnter;
X		case 'Z':	return KEY_BackTab;
X
X		/* VT[12]00 PF keys */
X		case 'P': case 'Q': case 'R': case 'S':
X			return KEY_PF1 + (c - 'P');
X
X		/* VT[12]00 keypad */
X		case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
X		case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y':
X			return KEY_PadComma + (c - 'l');
X
X		default:
X			beep();
X			state = NORMAL;
X			}
X		break;
X
X	case ESCAPE:
X		switch (c) {
X		case 'O':
X		case '[':
X			state = FKEY;
X			fkeycount = 0;
X			break;
X
X		default:
X			state = NORMAL;
X			beep();
X			}
X		break;
X
X	default:
X		switch (c) {
X		case Escape:
X			state = ESCAPE;
X			break;
X
X		case CSI:
X			state = FKEY;
X			fkeycount = 0;
X			break;
X
X		default:
X			return (c);
X			}
X		}
X	}
X}
END_OF_FILE
  if test 3184 -ne `wc -c <'getch.c'`; then
    echo shar: \"'getch.c'\" unpacked with wrong size!
  fi
  # end of 'getch.c'
fi
if test -f 'getch.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'getch.h'\"
else
  echo shar: Extracting \"'getch.h'\" \(4869 characters\)
  sed "s/^X//" >'getch.h' <<'END_OF_FILE'
X
X/*
X * This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
X *
X * Permission is hereby granted to copy, distribute or otherwise 
X * use any part of this package as long as you do not try to make 
X * money from it or pretend that you wrote it.  This copyright 
X * notice must be maintained in any copy made.
X *
X * Use of this software constitutes acceptance for use in an AS IS 
X * condition. There are NO warranties with regard to this software.  
X * In no event shall the author be liable for any damages whatsoever 
X * arising out of or in connection with the use or performance of this 
X * software.  Any use of this software is at the user's own risk.
X *
X * If you make modifications to this software that you feel 
X * increases it usefulness for the rest of the community, please 
X * email the changes, enhancements, bug fixes as well as any and 
X * all ideas to me. This software is going to be maintained and 
X * enhanced as deemed necessary by the community.
X *              
X *              Patrick J. Wolfe
X *              uunet!uiucuxc!kailand!pwolfe
X *              pwolfe@kailand.kai.com
X */
X
X#ifndef SYSVcurses
X/* System V curses key names and codes returned by getch */
X#define KEY_BREAK	0401
X#define KEY_DOWN	0402
X#define KEY_UP		0403
X#define KEY_LEFT	0404
X#define KEY_RIGHT	0405
X#define KEY_HOME	0406
X#define KEY_BACKSPACE	0407
X#define KEY_F0		0410	/* function keys */
X#define KEY_F(x)	(KEY_F0 + (x))	/* space for 64 function keys is reserved */
X#define KEY_DL		0510	/* delete line */
X#define KEY_IL		0511	/* insert line */
X#define KEY_DC		0512	/* delete char */
X#define KEY_IC		0513	/* insert char or enter insert mode */
X#define KEY_EIC		0514	/* exit insert mode */
X#define KEY_CLEAR	0515	/* clear screen */
X#define KEY_EOS		0516	/* clear to end of screen */
X#define KEY_EOL		0517	/* clear to end of line */
X#define KEY_SF		0520	/* scroll 1 line forward */
X#define KEY_SR		0521	/* scroll 1 line backward (reverse) */
X#define KEY_NPAGE	0522	/* next page */
X#define KEY_PPAGE	0523	/* previous page */
X#define KEY_STAB	0524	/* set tab */
X#define KEY_CTAB	0525	/* clear tab */
X#define KEY_CATAB	0526	/* clear all tabs */
X#define KEY_ENTER	0527	/* Enter or send (unreliable) */
X#define KEY_SRESET	0530	/* soft (partial) reset (unreliable) */
X#define KEY_RESET	0531	/* reset or hard reset (unreliable) */
X#define KEY_PRINT	0532	/* print or copy */
X#define KEY_LL		0533	/* home down or bottom (lower left) */
X#endif /* NOT SYSVcurses */
X
X/* vt220 special keys */
X
X#define KEY_F1		0411
X#define KEY_F2		0412
X#define KEY_F3		0413
X#define KEY_F4		0414
X#define KEY_F5		0415
X#define KEY_F6		0416
X#define KEY_F7		0417
X#define KEY_F8		0420
X#define KEY_F9		0421
X#define KEY_F10		0422
X#define KEY_F11		0423
X#define KEY_F12		0424
X#define KEY_F13		0425
X#define KEY_F14		0426
X#define KEY_F15		0427
X#define KEY_Help	0427
X#define KEY_F16		0430
X#define KEY_Do		0430
X#define KEY_F17		0431
X#define KEY_F18		0432
X#define KEY_F19		0433
X#define KEY_F20		0434
X#define KEY_PF1		0534
X#define KEY_PF2		0535
X#define KEY_PF3		0536
X#define KEY_PF4		0537
X#define KEY_Pad0	0540
X#define KEY_Pad1	0541
X#define KEY_Pad2	0542
X#define KEY_Pad3	0543
X#define KEY_Pad4	0544
X#define KEY_Pad5	0545
X#define KEY_Pad6	0546
X#define KEY_Pad7	0547
X#define KEY_Pad8	0550
X#define KEY_Pad9	0551
X#define KEY_PadEnter	0552
X#define KEY_PadMinus	0553
X#define KEY_PadPeriod	0554
X#define KEY_PadComma	0555
X#define KEY_Pad00	0556
X#define KEY_BackTab	0557
X#define KEY_Find	0560
X#define KEY_InsertHere	0561
X#define KEY_Remove	0562
X#define KEY_Select	0563
X#define KEY_PrevScreen	0564
X#define KEY_PrevScrn	0564
X#define KEY_NextScreen	0565
X#define KEY_NextScrn	0565
X#define KEY_SF1		0611
X#define KEY_SF2		0612
X#define KEY_SF3		0613
X#define KEY_SF4		0614
X#define KEY_SF5		0615
X#define KEY_SF6		0616
X#define KEY_SF7		0617
X#define KEY_SF8		0620
X#define KEY_SF9		0621
X#define KEY_SF10	0622
X#define KEY_SF11	0623
X#define KEY_SF12	0624
X#define KEY_SF13	0625
X#define KEY_SF14	0626
X#define KEY_SF15	0627
X#define KEY_SHelp	0627
X#define KEY_SF16	0630
X#define KEY_SDo		0630
X#define KEY_SF17	0631
X#define KEY_SF18	0632
X#define KEY_SF19	0633
X#define KEY_SF20	0634
X
X/* ascii control codes */
X#define ControlA	001
X#define ControlB	002
X#define ControlC	003
X#define ControlD	004
X#define ControlE	005
X#define ControlF	006
X#define ControlG	007
X#define ControlH	010
X#define BackSpace	010
X#define ControlI	011
X#define Tab		011
X#define ControlJ	012
X#define LineFeed	012
X#define ControlK	013
X#define ControlL	014
X#define ControlM	015
X#define Return		015
X#define ControlN	016
X#define ControlO	017
X#define ControlP	020
X#define ControlQ	021
X#define ControlR	022
X#define ControlS	023
X#define ControlT	024
X#define ControlU	025
X#define ControlV	026
X#define ControlW	027
X#define ControlX	030
X#define ControlY	031
X#define ControlZ	032
X#define Escape		033
X#define Control[	033
X#define Delete		0177
X#define Del		0177
X#define CSI		0233
END_OF_FILE
  if test 4869 -ne `wc -c <'getch.h'`; then
    echo shar: \"'getch.h'\" unpacked with wrong size!
  fi
  # end of 'getch.h'
fi
if test -f 'main.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'main.c'\"
else
  echo shar: Extracting \"'main.c'\" \(4197 characters\)
  sed "s/^X//" >'main.c' <<'END_OF_FILE'
X/*
X *	scan - file menu program
X *
X * This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
X *
X * Permission is hereby granted to copy, distribute or otherwise 
X * use any part of this package as long as you do not try to make 
X * money from it or pretend that you wrote it.  This copyright 
X * notice must be maintained in any copy made.
X *
X * Use of this software constitutes acceptance for use in an AS IS 
X * condition. There are NO warranties with regard to this software.  
X * In no event shall the author be liable for any damages whatsoever 
X * arising out of or in connection with the use or performance of this 
X * software.  Any use of this software is at the user's own risk.
X *
X * If you make modifications to this software that you feel 
X * increases it usefulness for the rest of the community, please 
X * email the changes, enhancements, bug fixes as well as any and 
X * all ideas to me. This software is going to be maintained and 
X * enhanced as deemed necessary by the community.
X *              
X *              Patrick J. Wolfe
X *              uunet!uiucuxc!kailand!pwolfe
X *              pwolfe@kailand.kai.com
X */
X
X
X#include "config.h"
X#include "defkeys.h"
X
Xextern char *getenv();
Xextern struct option_entry option_table[];
Xextern char currdir[];
X
Xstruct key_entry keytab[SIZEKEYTAB];
Xint opt_auto_untag, opt_dir_order, opt_dot_order, opt_dotdir_order, opt_hide_dotdot,
X	opt_pager_pause, opt_rm_prompt, opt_show_filetype, opt_show_symlinks;
Xchar *editor = DEFAULT_EDITOR, *pager = DEFAULT_PAGER, *loginid, *shellpgm, *homedir;
Xchar rcfilename[MAXPATHLEN];
Xint namebufleft = BUFSIZE;
Xint PAGESIZE = 0;
Xchar *namebuf;
X
X
X/*
X * initialize key definition and option tables
X */
Xinit_defaults ()
X{
Xint ctr;
X
Xbcopy ((char *) default_keytab, (char *) keytab, (sizeof(struct key_entry) * SIZEKEYTAB));
X/*
Xfor (ctr = 0; ctr < SIZEKEYTAB; ctr++) {
X	keytab[ctr].type = default_keytab[ctr].type;
X	keytab[ctr].options = default_keytab[ctr].options;
X	keytab[ctr].pntr = default_keytab[ctr].pntr;
X	}
X*/
X
Xfor (ctr = 0; option_table[ctr].name != NULL; ctr++) {
X	*option_table[ctr].variable = option_table[ctr].default_value;
X	}
X}
X
X
XSIGTYPE
Xdie ()
X{
Xmove (LINES, 0);
Xrefresh ();
Xendwin();
Xexit (0);
X}
X
X
Xmain (argc, argv)
Xint	argc;
Xchar	**argv;
X{
Xstruct	passwd	*pb;
Xchar *fieldval;
X
X#ifdef SYSVgetcwd
Xgetcwd (currdir, MAXPATHLEN);
X#else
Xgetwd (currdir);
X#endif /* SYSVgetcwd */
X
Xif ((argc > 1) && (chdir (argv[1]) == -1)) {
X	perror ("chdir");
X	fprintf (stderr, "scan:  cannot cd to directory %s\n", argv[1]);
X	exit (1);
X	}
X
Xif ((pb = getpwuid (getuid())) == NULL) {
X	perror ("getpwuid");
X	fprintf (stderr, "scan:  you do not have an account on this system\n");
X	exit (1);
X	}
X
X/* get some environment variables */
Xif (((fieldval = getenv("USER")) != NULL) || ((fieldval = getenv("LOGNAME")) != NULL)) {
X	loginid = (char *) malloc (strlen(fieldval)+1);
X	strcpy (loginid, fieldval);
X	}
Xelse if ((fieldval = (char *) getlogin()) != NULL) {
X	loginid = (char *) malloc (strlen(fieldval)+1);
X	strcpy (loginid, fieldval);
X	}
Xelse	{
X	loginid = (char *) malloc (strlen(pb->pw_name)+1);
X	strcpy (loginid, pb->pw_name);
X	}
X
Xif ((fieldval = getenv("EDITOR")) != NULL) {
X	editor = (char *) malloc (strlen(fieldval)+1);
X	strcpy (editor, fieldval);
X	}
X
Xif ((fieldval = getenv("PAGER")) != NULL) {
X	pager = (char *) malloc (strlen(fieldval)+1);
X	strcpy (pager, fieldval);
X	}
X
Xif ((fieldval = getenv("SHELL")) != NULL) {
X	shellpgm = (char *) malloc (strlen(fieldval)+1);
X	strcpy (shellpgm, fieldval);
X	}
Xelse	{
X	shellpgm = (char *) malloc (strlen(pb->pw_shell)+1);
X	strcpy (shellpgm, pb->pw_shell);
X	}
X
Xif ((fieldval = getenv("HOME")) != NULL) {
X	homedir = (char *) malloc (strlen(fieldval)+1);
X	strcpy (homedir, fieldval);
X	}
Xelse	{
X	homedir = (char *) malloc (strlen(pb->pw_dir)+1);
X	strcpy (homedir, pb->pw_dir);
X	}
X
Xif ((namebuf = (char *) malloc (BUFSIZE)) == NULL) {
X	perror ("malloc");
X	exit (1);
X	}
X
Xinit_defaults ();		/* initialize key and option tables */
Xreadrc (SYSTEM_RCFILE);		/* read system init file */
Xstrcpy (rcfilename, homedir);
Xstrcat (rcfilename, "/.scanrc");
Xreadrc (rcfilename);		/* read user init file */
X
Xmain_loop ();			/* the program's main routine */
X/* NOTREACHED */
X}
END_OF_FILE
  if test 4197 -ne `wc -c <'main.c'`; then
    echo shar: \"'main.c'\" unpacked with wrong size!
  fi
  # end of 'main.c'
fi
if test -f 'readrc.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'readrc.h'\"
else
  echo shar: Extracting \"'readrc.h'\" \(7455 characters\)
  sed "s/^X//" >'readrc.h' <<'END_OF_FILE'
X
X/*
X * This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
X *
X * Permission is hereby granted to copy, distribute or otherwise 
X * use any part of this package as long as you do not try to make 
X * money from it or pretend that you wrote it.  This copyright 
X * notice must be maintained in any copy made.
X *
X * Use of this software constitutes acceptance for use in an AS IS 
X * condition. There are NO warranties with regard to this software.  
X * In no event shall the author be liable for any damages whatsoever 
X * arising out of or in connection with the use or performance of this 
X * software.  Any use of this software is at the user's own risk.
X *
X * If you make modifications to this software that you feel 
X * increases it usefulness for the rest of the community, please 
X * email the changes, enhancements, bug fixes as well as any and 
X * all ideas to me. This software is going to be maintained and 
X * enhanced as deemed necessary by the community.
X *              
X *              Patrick J. Wolfe
X *              uunet!uiucuxc!kailand!pwolfe
X *              pwolfe@kailand.kai.com
X */
X
X
Xextern int opt_auto_untag, opt_dir_order, opt_dot_order, opt_dotdir_order, opt_hide_dotdot,
X	opt_pager_pause, opt_rm_prompt, opt_show_filetype, opt_show_symlinks;
X
X/* option value tables */
Xchar *true_false[] = { "false", "true", NULL };
Xchar *dot_order[] = { "first", "last", "hide", NULL };
Xchar *dir_order[] = { "first", "last", "sort", NULL };
Xchar *dotdir_order[] = { "withdot", "withdir", NULL };
X
X/* info about options used in init files and options menu */ 
Xstruct option_entry option_table[] = {
X	{ "auto-untag",		&opt_auto_untag,	true_false,	OPT_TRUE },
X	{ "dir-order",		&opt_dir_order,		dir_order,	DIR_FIRST },
X	{ "dot-order",		&opt_dot_order,		dot_order,	DOT_LAST },
X	{ "dotdir-order",	&opt_dotdir_order,	dotdir_order,	WITH_DOT },
X	{ "hide-dotdot",	&opt_hide_dotdot,	true_false,	OPT_FALSE },
X	{ "pager-pause",	&opt_pager_pause,	true_false,	OPT_TRUE },
X	{ "rm-prompt",		&opt_rm_prompt,		true_false,	OPT_TRUE },
X	{ "show-filetype",	&opt_show_filetype,	true_false,	OPT_TRUE },
X	{ "show-symlinks",	&opt_show_symlinks,	true_false,	OPT_TRUE },
X	{ NULL,			NULL,			NULL,		0 }
X	};
X
X/* info about built-in functions used in init files and keydef menu */
Xstruct funcname_entry funcname_table[] = {
X	{ "bottom_line",		bottom_line },
X	{ "cd_back",			cd_back },
X	{ "cd_dot",			cd_dot },
X	{ "cd_dotdot",			cd_dotdot },
X	{ "cd_file",			cd_file },
X	{ "cd_home",		 	cd_home },
X	{ "cd_prompt",		 	cd_prompt },
X	{ "cd_root",		 	cd_root },
X	{ "cd_or_edit",		 	cd_or_edit },
X	{ "cd_or_view",		 	cd_or_view },
X	{ "command_file",		command_file },
X	{ "command_tagged",		command_tagged },
X	{ "edit_file",			edit_file },
X	{ "edit_tagged",		edit_tagged },
X	{ "execute_file",		execute_file },
X	{ "exec_file",			exec_file },
X	{ "exit_pgm",			exit_pgm },
X	{ "first_page",			first_page },
X	{ "fork_shell",			fork_shell },
X	{ "help_screen",		help_screen },
X	{ "last_page",			last_page },
X	{ "middle_line",		middle_line },
X	{ "next_halfpage",		next_halfpage },
X	{ "next_line",			next_line },
X	{ "next_page",			next_page },
X	{ "prev_halfpage",		prev_halfpage },
X	{ "prev_line",			prev_line },
X	{ "prev_page",			prev_page },
X	{ "redraw_menu",		redraw_menu },
X	{ "rm_file",			rm_file },
X	{ "rm_tagged",			rm_tagged },
X	{ "setup_menu",			setup_menu },
X	{ "tag_all",		 	tag_all },
X	{ "toggle_tag",			toggle_tag },
X	{ "top_line",		 	top_line },
X	{ "untag_all",			untag_all },
X	{ "view_file",		 	view_file },
X	{ "view_tagged",	 	view_tagged },
X	{ "",				NULL }
X	};
X
X/* names of keys used in init files and keydef menu */
Xstruct keydef_entry keydef_table[] = {
X	{ "AndSign",	'&' },
X	{ "Asterisk",	'*' },
X	{ "AtSign",	'@' },
X	{ "BackQuote",	'`' },
X	{ "BackSpace",	ControlH },
X	{ "BackTab",	KEY_BackTab },
X	{ "BackTick",	'`' },
X	{ "Backslash",	'\\' },
X	{ "Bang",	'!' },
X	{ "Colon",	':' },
X	{ "Comma",	',' },
X	{ "ControlA",	ControlA },
X	{ "ControlB",	ControlB },
X	{ "ControlC",	ControlC },
X	{ "ControlD",	ControlD },
X	{ "ControlE",	ControlE },
X	{ "ControlF",	ControlF },
X	{ "ControlG",	ControlG },
X	{ "ControlH",	ControlH },
X	{ "ControlI",	ControlI },
X	{ "ControlJ",	ControlJ },
X	{ "ControlK",	ControlK },
X	{ "ControlL",	ControlL },
X	{ "ControlM",	ControlM },
X	{ "ControlN",	ControlN },
X	{ "ControlO",	ControlO },
X	{ "ControlP",	ControlP },
X	{ "ControlQ",	ControlQ },
X	{ "ControlR",	ControlR },
X	{ "ControlS",	ControlS },
X	{ "ControlT",	ControlT },
X	{ "ControlU",	ControlU },
X	{ "ControlV",	ControlV },
X	{ "ControlW",	ControlW },
X	{ "ControlX",	ControlX },
X	{ "ControlY",	ControlY },
X	{ "ControlZ",	ControlZ },
X	{ "Dash",	'-' },
X	{ "Delete",	Delete },
X	{ "Do",		KEY_F16 },
X	{ "DollarSign",	'$' },
X	{ "DoubleQuote",	'"' },
X	{ "DownArrow",	KEY_DOWN },
X	{ "Enter",	ControlM },
X	{ "Equals",	'=' },
X	{ "Exclamation",	'!' },
X	{ "ExclamationPoint",	'!' },
X	{ "F10",	KEY_F10 },
X	{ "F11",	KEY_F11 },
X	{ "F12",	KEY_F12 },
X	{ "F13",	KEY_F13 },
X	{ "F14",	KEY_F14 },
X	{ "F15",	KEY_F15 },
X	{ "F16",	KEY_F16 },
X	{ "F17",	KEY_F17 },
X	{ "F18",	KEY_F18 },
X	{ "F19",	KEY_F19 },
X	{ "F20",	KEY_F20 },
X	{ "F6",		KEY_F6 },
X	{ "F7",		KEY_F7 },
X	{ "F8",		KEY_F8 },
X	{ "F9",		KEY_F9 },
X	{ "Find",	KEY_Find },
X	{ "GreaterThan",	'>' },
X	{ "HatSign",	'^' },
X	{ "Help",	KEY_F15 },
X	{ "InsertHere",	KEY_InsertHere },
X	{ "KP0",	KEY_Pad0 },
X	{ "KP00",	KEY_Pad00 },
X	{ "KP1",	KEY_Pad1 },
X	{ "KP2",	KEY_Pad2 },
X	{ "KP3",	KEY_Pad3 },
X	{ "KP4",	KEY_Pad4 },
X	{ "KP5",	KEY_Pad5 },
X	{ "KP6",	KEY_Pad6 },
X	{ "KP7",	KEY_Pad7 },
X	{ "KP8",	KEY_Pad8 },
X	{ "KP9",	KEY_Pad9 },
X	{ "KPComma",	KEY_PadComma },
X	{ "KPEnter",	KEY_PadEnter },
X	{ "KPMinus",	KEY_PadMinus },
X	{ "KPPeriod",	KEY_PadPeriod },
X	{ "LeftArrow",	KEY_LEFT },
X	{ "LeftBrace",	'{' },
X	{ "LeftBracket",	'[' },
X	{ "LeftParen",	'(' },
X	{ "LessThan",	'<' },
X	{ "LineFeed",	ControlJ },
X	{ "Minus",	'-' },
X	{ "NextScreen",	KEY_NextScreen },
X	{ "PF1",	KEY_PF1 },
X	{ "PF2",	KEY_PF2 },
X	{ "PF3",	KEY_PF3 },
X	{ "PF4",	KEY_PF4 },
X	{ "Paren",	'(' },
X	{ "PercentSign",	'%' },
X	{ "Period",	'.' },
X	{ "Pipe",	'|' },
X	{ "Plus",	'+' },
X	{ "PrevScreen",	KEY_PrevScreen },
X	{ "Question",	'?' },
X	{ "QuestionMark",	'?' },
X	{ "Quote",	'\'' },
X	{ "Remove",	KEY_Remove },
X	{ "Return",	ControlM },
X	{ "RightArrow",	KEY_RIGHT },
X	{ "RightBrace",	'}' },
X	{ "RightBracket",	']' },
X	{ "RightParen",	')' },
X	{ "SDo",	KEY_SF16 },
X	{ "SF10",	KEY_SF10 },
X	{ "SF11",	KEY_SF11 },
X	{ "SF12",	KEY_SF12 },
X	{ "SF13",	KEY_SF13 },
X	{ "SF14",	KEY_SF14 },
X	{ "SF15",	KEY_SF15 },
X	{ "SF16",	KEY_SF16 },
X	{ "SF17",	KEY_SF17 },
X	{ "SF18",	KEY_SF18 },
X	{ "SF19",	KEY_SF19 },
X	{ "SF20",	KEY_SF20 },
X	{ "SF6",	KEY_SF6 },
X	{ "SF7",	KEY_SF7 },
X	{ "SF8",	KEY_SF8 },
X	{ "SF9",	KEY_SF9 },
X	{ "SHelp",	KEY_SF15 },
X	{ "Select",	KEY_Select },
X	{ "SemiColon",	';' },
X	{ "Sharp",	'#' },
X	{ "Slash",	'/' },
X	{ "Tab",	ControlI },
X	{ "Tilde",	'~' },
X	{ "UnParen",	')' },
X	{ "Underline",	'_' },
X	{ "UpArrow",	KEY_UP },
X	{ "^A",		ControlA },
X	{ "^B",		ControlB },
X	{ "^C",		ControlC },
X	{ "^D",		ControlD },
X	{ "^E",		ControlE },
X	{ "^F",		ControlF },
X	{ "^G",		ControlG },
X	{ "^H",		ControlH },
X	{ "^I",		ControlI },
X	{ "^J",		ControlJ },
X	{ "^K",		ControlK },
X	{ "^L",		ControlL },
X	{ "^M",		ControlM },
X	{ "^N",		ControlN },
X	{ "^O",		ControlO },
X	{ "^P",		ControlP },
X	{ "^Q",		ControlQ },
X	{ "^R",		ControlR },
X	{ "^S",		ControlS },
X	{ "^T",		ControlT },
X	{ "^U",		ControlU },
X	{ "^V",		ControlV },
X	{ "^W",		ControlW },
X	{ "^X",		ControlX },
X	{ "^Y",		ControlY },
X	{ "^Z",		ControlZ },
X	{ "",		0 }
X	};
END_OF_FILE
  if test 7455 -ne `wc -c <'readrc.h'`; then
    echo shar: \"'readrc.h'\" unpacked with wrong size!
  fi
  # end of 'readrc.h'
fi
if test -f 'runcmd.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'runcmd.c'\"
else
  echo shar: Extracting \"'runcmd.c'\" \(7729 characters\)
  sed "s/^X//" >'runcmd.c' <<'END_OF_FILE'
X/*
X *	runcmd.c - parse and execute commands (both builting and external)
X *
X * This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
X *
X * Permission is hereby granted to copy, distribute or otherwise 
X * use any part of this package as long as you do not try to make 
X * money from it or pretend that you wrote it.  This copyright 
X * notice must be maintained in any copy made.
X *
X * Use of this software constitutes acceptance for use in an AS IS 
X * condition. There are NO warranties with regard to this software.  
X * In no event shall the author be liable for any damages whatsoever 
X * arising out of or in connection with the use or performance of this 
X * software.  Any use of this software is at the user's own risk.
X *
X * If you make modifications to this software that you feel 
X * increases it usefulness for the rest of the community, please 
X * email the changes, enhancements, bug fixes as well as any and 
X * all ideas to me. This software is going to be maintained and 
X * enhanced as deemed necessary by the community.
X *              
X *              Patrick J. Wolfe
X *              uunet!uiucuxc!kailand!pwolfe
X *              pwolfe@kailand.kai.com
X */
X
X
X#include "config.h"
X
Xextern SIGTYPE die();
X#ifdef NEED_TSTP
X#define TSTP_RTN _tstp
X#else
X#define TSTP_RTN tstp
X#endif
Xextern SIGTYPE TSTP_RTN();
Xextern struct dblock cwd[];
Xextern WINDOW *headwin, *datawin, *helpwin;
Xextern int lastptr, curptr, opt_auto_untag;
X
X
X/*
X *	1.  Break command line into arguments
X *		Copies command to "command_line", placing null's between arguments,
X *		and adding pointers to "arglist" to the beginning of each argument.
X *		Counts the number of arguments found.
X *
X *	2.  Append filenames to the command
X *		Depending on the options specified, add the current filename, all
X *		tagged filenames, or no filenames to the end of the built command.
X *
X *	3.  Run the passed command.
X */
Xvoid
Xdo_cmd (command, options)
Xchar	*command;
Xint	options;
X{
Xunion	wait	status;
Xint	argc, ctr1, ctr2, row = 2, cpid, dpid;
Xint c;
Xchar	*ptr1, *ptr2, *arglist[MAXARGS],
X	command_line[10240];
X
Xmvcur (0, COLS-1, LINES-1, 0);
Xrefresh ();
Xargc = 0;
Xptr1 = command;
Xptr2 = command_line;
X
Xwhile (1) {
X	/* skip over white space */
X	for (; (*ptr1 != '\0') && isspace(*ptr1); ptr1++);
X	if (*ptr1 == '\0') {
X		break;
X		}
X
X	/* mark beginning of argument */
X	arglist[argc] = ptr2;
X#ifdef DEBUG
X	fprintf (stderr, "starting argument %d at %s\n", argc, ptr1);
X#endif
X
X	/* find end of current argument */
X	for (ctr1 = ctr2 = 0; *ptr1 != '\0'; ptr1++, ptr2++) {
X		if (isspace (*ptr1) && (ctr1 == 0) && (ctr2 == 0)) {
X			break;		/* stop at first whitespace outsite quotes */
X			}
X		if (*ptr1 == '\\') {
X			ptr1++;
X			if (*ptr1 == '\0') {
X				break;	/* the line ends in a bad old backslash */
X				}
X			}
X		else if ((*ptr1 == '"') && (ctr2 == 0)) {	/* keep track of double quotes */
X			ctr1 = (ctr1 * -1) + 1;
X			}
X		else if ((*ptr1 == '\'') && (ctr1 == 0)) {	/* keep track of single quotes */
X			ctr2 = (ctr2 * -1) + 1;
X			}
X		*ptr2 = *ptr1;
X		}
X
X	/* mark end of current argument, and advance to next char */
X	*ptr2 = '\0';
X	ptr2++;
X
X#ifdef DEBUG
X	fprintf (stderr, "arg %d length=%d bytes, value = \"%s\"\n", argc, strlen(arglist[argc]), arglist[argc]);
X	sleep (2);
X#endif
X
X	/* check to see if this is the special argument of a pair of curly or hard braces */
X	if ((strlen(arglist[argc]) == 2) && (((arglist[argc][0] == '{') && (arglist[argc][1] == '}'))
X		|| ((arglist[argc][0] == '[') && (arglist[argc][1] == ']')))) {
X		options &= OPT_TAGALL;	/* turn off tag all and tag current options */
X		options &= OPT_TAGCUR;
X		/* replace this argument with the list of all tagged files */
X		for (ctr1 = 0; (ctr1 <= lastptr) && (argc < MAXARGS); ctr1++) {
X			if (cwd[ctr1].selected) {
X				arglist[argc++] = cwd[ctr1].name;
X				if (opt_auto_untag) {
X					cwd[ctr1].selected = 0;
X					}
X				}
X			}
X		}
X	else	{
X		argc++;
X		}
X
X	/* if at end of input command, stop here */
X	if (*ptr1 == '\0') {
X		break;
X		}
X	}
X
Xif (argc == 0) {
X	return;		/* no command to execute */
X	}
X
Xif (options & OPT_TAGCUR) {		/* append filename currently being pointed at to the command */
X	arglist[argc++] = cwd[curptr].name;
X	cwd[curptr].size = -1;			/* set flag so this file gets re-stat'd */
X	}
X
Xelse if (options & OPT_TAGALL) {	/* append names of all tagged files to the command */
X	for (ctr2 = 0; (ctr2 <= lastptr) && (argc < MAXARGS); ctr2++) {
X		if (cwd[ctr2].selected) {
X			arglist[argc++] = cwd[ctr2].name;
X			if (opt_auto_untag) {
X				cwd[ctr2].selected = 0;
X				}
X			cwd[ctr2].size = -1;	/* set flag so these files get re-stat'd */
X			}
X		}
X	}
X
Xarglist[argc] = 0;
X
X/* clear the screen, reset the terminal to normal mode, and run the command */
Xwmove (helpwin, 0, 0);
Xwclrtobot (helpwin);
Xwrefresh (helpwin);
Xwmove (datawin, 0, 0);
Xwclrtobot (datawin);
Xwrefresh (datawin);
Xwmove (headwin, row, 0);
Xwclrtobot (headwin);
Xwmove (headwin, row, 0);
X
X/* let the user know what we are doing */
Xwaddstr (headwin, "Running the command: ");
Xfor (ctr1 = 0, ctr2 = 0; (row <= 3) && (arglist[ctr1] != 0); ctr1++) {
X	ctr2 += 1 + strlen (arglist[ctr1]);
X	if (ctr2 > 79) {
X		row++;
X		wmove (headwin, row, 4);
X		ctr2 = 4 + strlen (arglist[ctr1]);
X		}
X	else	{
X		waddch (headwin, ' ');
X		}
X	waddstr (headwin, arglist[ctr1]);
X	}
X
Xif (options & OPT_VERIFY) {
X	c = 'a';
X	while ((c != 'y') && (c != 'Y') && (c != 'N') && (c != 'n')) {
X		wmove (headwin, 4, 0);
X		waddstr (headwin, "Are you sure? ");
X		wrefresh (headwin);
X		c = my_getch (headwin);
X		}
X	if ((c != 'y') && (c != 'Y')) {
X		redraw_menu ();
X		return;
X		}
X	}
Xelse
X	wrefresh (headwin);
X
Xwmove (datawin, 0, 0);
Xwrefresh (datawin);
X#ifdef SYSVcurses
Xdelwin (datawin);
Xdelwin (helpwin);
Xdelwin (helpwin);
Xendwin();		/* terminate curses */
X#else /* ! SYSVcurses */
Xecho ();		/* echo keys as they are typed */
Xnl ();			/* enable cr/lf mapping */
Xnocrmode ();		/* turn off cbreak mode */
X#endif /* SYSVcurses */
Xsignal (SIGHUP, SIG_DFL);			/* trap signal 1, hangup */
Xsignal (SIGINT, SIG_DFL);			/* trap signal 2, interrupt */
Xsignal (SIGQUIT, SIG_DFL);			/* trap signal 3, quit */
Xsignal (SIGTERM, SIG_DFL);			/* trap signal 15, software termination */
Xsignal (SIGTSTP, SIG_IGN);			/* trap signal 15, software termination */
X
Xif ((cpid = fork()) == 0) {
X	execvp (arglist[0], arglist);
X	perror ("execvp");
X	fprintf (stderr, "scan:  cannot execute %s\r\n", arglist[0]);
X	exit (-1);
X	}
Xif (cpid == -1) {
X	perror ("fork");
X	exit (-1);
X	}
Xsignal (SIGINT, SIG_IGN);			/* restore signal 2, interrupt */
Xsignal (SIGQUIT, SIG_IGN);			/* restore signal 3, quit */
X
X/* wait until our baby dies */
Xdo	{
X	dpid = wait (&status);
X	} while ((dpid != cpid) && (dpid != -1));
X
Xif (status.w_T.w_Termsig != 0) {
X	fprintf (stderr, "\r\ncommand was killed by signal #%d ", status.w_T.w_Termsig);
X	}
Xelse if (status.w_T.w_Retcode != 0) {
X	fprintf (stderr, "\r\ncommand returned error status code %d", status.w_T.w_Retcode);
X	}
X
X#ifdef SYSVcurses
Xinitscr ();			/* initialize curses */
X#endif
Xsignal (SIGHUP, die);		/* trap signal 1, hangup */
Xsignal (SIGINT, die);		/* trap signal 2, interrupt */
Xsignal (SIGQUIT, die);		/* trap signal 3, quit */
Xsignal (SIGTERM, die);		/* trap signal 15, software termination */
Xsignal (SIGTSTP, TSTP_RTN);	/* trap tstp signal */
Xnoecho ();			/* curses should not echo keys as they are typed */
Xnonl ();			/* disable cr/lf mapping */
Xcrmode ();			/* turn on cbreak mode */
X#ifdef SYSVcurses
Xheadwin = newwin (5, COLS, 0, 0);
Xdatawin = newwin (PAGESIZE, COLS, 5, 0);
Xhelpwin = newwin (1, COLS, PAGESIZE + 5, 0);
Xidlok (datawin, TRUE);
X#endif
X
Xif ( (options & OPT_WAIT) || ((options & OPT_WAITERR) && (status.w_T.w_Retcode != 0)) ) {
X	fprintf (stderr, " -- press Return to continue");
X	my_getch (headwin);
X	}
X
Xredraw_menu ();
X}
END_OF_FILE
  if test 7729 -ne `wc -c <'runcmd.c'`; then
    echo shar: \"'runcmd.c'\" unpacked with wrong size!
  fi
  # end of 'runcmd.c'
fi
if test -f 'scan.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'scan.1'\"
else
  echo shar: Extracting \"'scan.1'\" \(8428 characters\)
  sed "s/^X//" >'scan.1' <<'END_OF_FILE'
X...
X.TH SCAN 1 "4.0" "Usenet software" "Usenet software"
X
X.SH NAME
Xscan - directory menu
X
X.SH SYNOPSIS
Xscan [directory]
X
X.SH DESCRIPTION
X.I Scan
Xdisplays a menu containing information about all the files contained in
Xa directory, and lets you perform common operations on them.
X
XYou may optionally specify a directory name to begin with.
XWith no directory names on the command line,
X.I scan
Xwill begin in the current directory.
X
X.SH "WHAT'S ON THE SCREEN"
XThe screen that
X.I Scan
Xdisplays can be broken into to three areas.
X
XThe top few lines display the program's
Xname and version number, your login id, the date and time, and
Xthe occational error message.  Also shown is
Xthe name of current directory, the total
Xnumber of files in the directory, and the number of hidden files (if any).
XHidden files are "dot files" which aren't currently being shown (see the
XOPTIONS section later).
X
XThe last line of the display is used to display some help.
X
XThe rest of the screen is used by the file menu.
X
X.SH "USING THE FILE MENU"
XThe file menu resembles the output of an "ls -l" command.  Displayed are
Xthe file's permissions, owner and group name, size (in bytes),
Xthe date of the most recent modification, and filename.  If the name
Xis too long, it may be truncated in the display.  If the "show-filetype"
Xoption is turned on, a slash will be appended to subdirectory names,
Xand an asterisk to executable files.  If the "show-symlinks"
Xoption is turned on, symbolic links will display the file the link points to
Xafter the file name.
X
XSome functions of Scan operate on the current file.
XThe "current file" is what we call the file which has the little arrow ("=>") pointing to
Xit's name.  The up and down arrow keys (also the "j" and "k" keys) move the current file
Xpointer up and down on the file menu.
X
XFiles may also be "tagged".
XWhen a file is "tagged", it's line on the screen is highlighted.
XSome functions of Scan operate on all tagged files at once.
XThe "m" key toggles the "tagged" status of any file.
XTagged files are discussed more fully in the section "USING THE TAG FEATURE".
X
XThere are a number of ways to move around the file menu display:
X
X.br
Xcontrol-F
X.br
X.in +10
Xscroll forward (down) one screen
X.in -10
X.br
Xcontrol-B
X.br
X.in +10
Xscroll backward (up) one screen
X.in -10
X.br
Xcontrol-D
X.br
X.in +10
Xscroll down one half screen
X.in -10
X.br
Xcontrol-U
X.br
X.in +10
Xscroll up one half screen
X.in -10
X.br
X"down-arrow" or "j"
X.br
X.in +10
Xmoves down one file on the menu
X.in -10
X.br
X"up-arrow" or "k"
X.br
X.in +10
Xmoves up one file on the menu
X.in -10
X.br
X"g"
X.br
X.in +10
X(top) moves to the first page of the menu
X.in -10
X.br
X"G"
X.br
X.in +10
X(bottom) moves to the last page of the menu
X.in -10
X.br
X"H"
X.br
X.in +10
X(high) moves to the first line of the current page
X.in -10
X.br
X"M"
X.br
X.in +10
X(middle) moves to the middle line of the current page
X.in -10
X.br
X"L"
X.br
X.in +10
X(low) moves to the last line of the current page
X.in -10
X.br
X
X
XThere are also several commands to change which directory you are "scanning":
X
X.br
X"d" or Return
X.br
X.in +10
X(down) change directory to the current file (the file the "==>" is pointing to)
X.in -10
X.br
X"u"
X.br
X.in +10
X(up) change directory to the parent of the current directory
X.in -10
X.br
X"b"
X.br
X.in +10
X(back) change directory to the last directory you "scanned"
X.in -10
X.br
X"c"
X.br
X.in +10
X(cd) prompts for a directory path to cd to.
X.in -10
X.br
X"/"
X.br
X.in +10
Xchange directory to the root directory
X.in -10
X.br
X"~"
X.br
X.in +10
Xchange directory to your home directory
X.in -10
X.br
X"."
X.br
X.in +10
Xre-scans the current directory (useful if some files where added or deleted)
X.in -10
X
XHere are a few common actions that you can do to a file, without using the command line.
XThe "tag" feature is described in more detail in the section "USING THE TAG FEATURE".
X
X.br
X"e" or Return
X.br
X.in +10
Xedits the current file.  It will use the value of the "EDITOR"
Xenvironment variable, if this is set, and defaults to "vi".
X.in -10
X.br
X"v"
X.br
X.in +10
Xview the current file.  It will use the value of the "PAGER"
Xenvironment variable, if this is set, and defaults to "more".
X.in -10
X.br
X"r"
X.br
X.in +10
Xremoves the current file, after verifying with you that this is okay.
X.in -10
X.br
X"x"
X.br
X.in +10
Xprompts for a command, and executes it appending the current filename
X.in -10
X.br
X"E", "V", "R" and "X"
X.br
X.in +10
Xare the same as "e", "v", "r" and "x", except that they work
Xon all the tagged files, instead of just the current file.
X.in -10
X.br
X"m" or LineFeed
X.br
X.in +10
Xtoggles the "tagged" status of the current file.
X.in -10
X.br
X"T"
X.br
X.in +10
Xtags every file.
X.in -10
X.br
X"U"
X.br
X.in +10
Xuntags every file.
X.in -10
X.br
X
X
XThe rest of the commands perform miscellaneous tasks:
X
X.br
X"S"
X.br
X.in +10
XEnter the SETUP mode, used to change key definitions or option values
X.in -10
X.br
X"q" or "Q"
X.br
X.in +10
Xquit the Scan program.
X.in -10
X.br
X"!" or "%"
X.br
X.in +10
Xforks a shell (using your SHELL)
X.in -10
X.br
X"control-L" or "control-R"
X.br
X.in +10
Xredraws the screen
X.in -10
X.br
X
X.SH "USING THE TAG FEATURE"
XTagging files is an easy way to operate on multiple files at one time.
X
XYou can tag files by moving the current file pointer and pressing the "m"
Xkey.  Tagged files are highlighted on the screen.  The "m" key toggles the tagged status
Xof a file, so to un-tag a file, just press "m" again.  The "T" key tags all files (except hidden files) in the
Xcurrent directory, and "U" untags all files.
X
XSome of the file menu commands (C,E,R,V) operate on all tagged files at once.
X
XFor example, you can edit a whole range of files by moving up and down the file menu, tagging all
Xthe files you want to edit, and then pressing "E".
X
XAfter a commands which uses tagged files is executed, all files are un-tagged automatically, unless
Xthe "auto-untag" option is turned off.
X
X.SH SETUP
XThe "setup_menu" lets you choose between defining keys and changing values of options.  Once you
Xhave customized options and keys to your desire, remember to save your changes.  A ".scanrc" file
Xwill be written for you.
X
XThere are several options which you may want to change:
X
X.br
X	option		valid values (*=default value)
X.br
X	------		------------------------------
X.br
X	auto_untag	*true, false
X.br
X                        If true, operations on tagged files cause the files to be untagged.
X.br
X	dir_order	first, last, *sort
X.br
X                        Where to put the directory names in the file menu, top, bottom, or sorted (like ls)
X.br
X	dot_order	first, *last, hide
X.br
X                        Where to put the dot files, at top of list, bottom of list, or hide them
X.br
X	dotdir_order	*withdot, withdir
X.br
X                        Where to put dot-directory names, with dot files or with other directories
X.br
X	hide_dotdot	*true, false
X.br
X                        If true, "." and ".." are not shown
X.br
X	pause_pager	*true, false
X.br
X                        If true, pauses after your "PAGER" is executed
X.br
X	rm_prompt	*true, false
X.br
X                        If true, verifies before removing files or directories
X.br
X	show_filetype	*true, false
X.br
X                        If true, appends "/" to directory names and "*" to executable files
X.br
X	show_symlinks	*true, false
X.br
X                        If true, shows files that symbolic links point to
X
X.SH ORIGIN
XThe first Unix version of
X.I scan
Xwas written in 1989 in the C language by Patrick Wolfe (pat@kai.com,
Xkailand!pat).
XVersion 4 was updated in April 1991 and release to the Usenet
Xcommunity in May 1991.
X
X.SH COPYRIGHT
X.I Scan
Xis Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
X
XPermission is hereby granted to copy, distribute or otherwise 
Xuse any part of this package as long as you do not try to make 
Xmoney from it or pretend that you wrote it.  This copyright 
Xnotice must be maintained in any copy made.
X
XUse of this software constitutes acceptance for use in an AS IS 
Xcondition. There are NO warranties with regard to this software.  
XIn no event shall the author be liable for any damages whatsoever 
Xarising out of or in connection with the use or performance of this 
Xsoftware.  Any use of this software is at the user's own risk.
X
XIf you make modifications to this software that you feel 
Xincreases it usefulness for the rest of the community, please 
Xemail the changes, enhancements, bug fixes as well as any and 
Xall ideas to me. This software is going to be maintained and 
Xenhanced as deemed necessary by the community.
X
END_OF_FILE
  if test 8428 -ne `wc -c <'scan.1'`; then
    echo shar: \"'scan.1'\" unpacked with wrong size!
  fi
  # end of 'scan.1'
fi
if test -f 'setupmenu.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'setupmenu.c'\"
else
  echo shar: Extracting \"'setupmenu.c'\" \(2599 characters\)
  sed "s/^X//" >'setupmenu.c' <<'END_OF_FILE'
X
X/*
X * This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
X *
X * Permission is hereby granted to copy, distribute or otherwise 
X * use any part of this package as long as you do not try to make 
X * money from it or pretend that you wrote it.  This copyright 
X * notice must be maintained in any copy made.
X *
X * Use of this software constitutes acceptance for use in an AS IS 
X * condition. There are NO warranties with regard to this software.  
X * In no event shall the author be liable for any damages whatsoever 
X * arising out of or in connection with the use or performance of this 
X * software.  Any use of this software is at the user's own risk.
X *
X * If you make modifications to this software that you feel 
X * increases it usefulness for the rest of the community, please 
X * email the changes, enhancements, bug fixes as well as any and 
X * all ideas to me. This software is going to be maintained and 
X * enhanced as deemed necessary by the community.
X *              
X *              Patrick J. Wolfe
X *              uunet!uiucuxc!kailand!pwolfe
X *              pwolfe@kailand.kai.com
X */
X
X#include "config.h"
X
Xextern int redraw_menu();
Xextern int init_defaults();
Xextern int options_changed, keydef_changed;
Xextern char rcfilename[];
X
X
Xstatic void
Xsetup_redraw ()
X{
Xint row = 5;
X
Xclear();
Xmvaddstr (1, 30, PGM_VERSION);
Xaddstr (" Setup Menu");
Xmvaddstr (row++, 30, "K - key definition menu");
Xmvaddstr (row++, 30, "O - options menu");
Xmvaddstr (row++, 30, "S - save changes to setup");
Xmvaddstr (row++, 30, "D - restore default setup");
Xmvaddstr (row++, 30, "Q - save changes and exit setup");
Xmvaddstr (row, 30, "X - exit setup without saving changes");
Xrefresh ();
X}
X
X
Xsave_setup ()
X{
Xmvaddstr (3, 10, "saving setup ... please wait");
Xrefresh ();
X
Xwriterc ();
Xoptions_changed = keydef_changed = 0;
X
Xmove (3, 10);
Xclrtoeol ();
Xmvprintw (3, 10, "Your setup has been saved");
Xrefresh ();
X}
X
X
Xsetup_menu ()
X{
Xint c;
X
Xsetup_redraw ();
Xwhile (1) {
X	c = my_getch (stdscr);
X	switch (c) {
X	case 'D':
X	case 'd':
X		init_defaults ();
X		break;
X
X	case 'K':
X	case 'k':
X		clear ();
X		refresh ();
X		keydef_menu ();
X		setup_redraw ();
X		break;
X
X	case 'O':
X	case 'o':
X		clear ();
X		refresh ();
X		options_menu ();
X		setup_redraw ();
X		break;
X
X	case 'S':
X	case 's':
X		save_setup ();
X		break;
X
X	case 'Q':
X	case 'q':
X		if (options_changed || keydef_changed) {
X			save_setup ();
X			do_chdir (".");
X			}
X		else
X			redraw_menu();
X		return;
X		
X	case 'X':
X	case 'x':
X		if (options_changed)
X			do_chdir (".");
X		else
X			redraw_menu();
X		return;
X
X	default:
X		fprintf (stderr, "\007");
X		}
X	}
X}
END_OF_FILE
  if test 2599 -ne `wc -c <'setupmenu.c'`; then
    echo shar: \"'setupmenu.c'\" unpacked with wrong size!
  fi
  # end of 'setupmenu.c'
fi
echo shar: End of archive 3 \(of 3\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 3 archives.
    rm -f ark[1-9]isdone
else
    echo You still must unpack the following archives:
    echo "        " ${MISSING}
fi
exit 0
exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.