home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: kent@sparky.sterling.com (Kent Landfield)
- Subject: v39i067: lc - Categorize and List Files In Columns, Patch02
- Message-ID: <1993Aug30.120931.22445@sparky.sterling.com>
- X-Md4-Signature: 10fe89d587fd2a1817d212c558904282
- Sender: kent@sparky.sterling.com (Kent Landfield)
- Organization: Sterling Software
- Date: Mon, 30 Aug 1993 12:09:31 GMT
- Approved: kent@sparky.sterling.com
-
- Submitted-by: kent@sparky.sterling.com (Kent Landfield)
- Posting-number: Volume 39, Issue 67
- Archive-name: lc/patch02
- Environment: UNIX, AmigaDOS, MINIX, Coherent, Cray, OSF/1
- Patch-To: lc: Volume 31, Issue 72-73
-
- This is the second patch to lc. This patch contains elements of creeping
- featurism... :-)
-
- o Adds the ability for lc to automagically determine the width of the
- display screen.
-
- o Adds support for the Cshell cdpath variable which behaves like the
- existing CDPATH functionality.
-
- Also, lc has been ported to OSF/1 using GCC. Anyone want to try putting it
- on BSDI or Linux ? If you do please let me know as I do not have access
- to those systems currently. Thanks.
-
- -Kent+
- ----
- diff -rc ../lc.p1/lc.1 ./lc.1
- *** ../lc.p1/lc.1 Sun Oct 18 17:04:02 1992
- --- ./lc.1 Sun Oct 18 21:15:08 1992
- ***************
- *** 1,4 ****
- ! .\" @(#)lc.1 1.8 8/20/92 Kent Landfield;
- .TH LC 1 "Usenet Source"
- .SH NAME
- .B lc
- --- 1,4 ----
- ! .\" @(#)lc.1 1.10 10/18/92 Kent Landfield;
- .TH LC 1 "Usenet Source"
- .SH NAME
- .B lc
- ***************
- *** 25,37 ****
- .B lc
- uses the environment variables
- .B LC,
- ! .B CDPATH
- and
- ! .B COLS
- ! to allow you to set up a default set of display options that
- .B lc
- ! should use each time is it run. Options on the command line override
- ! options specified in the environment if there is a conflict.
- .B LC
- is used to set
- .B lc
- --- 25,38 ----
- .B lc
- uses the environment variables
- .B LC,
- ! .B CDPATH,
- and
- ! .B cdpath
- ! to allow you to set up default display options which are used by
- .B lc
- ! each time is it run. Options on the command line override
- ! options specified in the environment if there is a conflict. The
- ! environment variable
- .B LC
- is used to set
- .B lc
- ***************
- *** 39,50 ****
- below can be used in setting default options within the environment
- variable
- .B LC.
- ! .B CDPATH
- ! is searched for a file not found at the requested location or
- ! in the current directory. This is an extremely handy feature of
- ! .B lc.
- .B COLS
- ! is used to switch the column width between 80 and 132 column display.
- .PP
- .B lc
- has incorporated the minimal the spell checking routines found in the book,
- --- 40,73 ----
- below can be used in setting default options within the environment
- variable
- .B LC.
- ! Depending on how its compiled,
- ! .B lc
- ! determines the screen width automagically. If your version was not compiled to use
- ! termcap library routines, the environment variable
- .B COLS
- ! is used to set the screen width.
- ! .B CDPATH
- ! and
- ! .B cdpath
- ! are searched for a file or directory not found at the requested location or
- ! within the current directory. This is an extremely handy feature of
- ! .B lc.
- ! The valid format of
- ! .B CDPATH
- ! is that of the standard Bourne/Korn shell syntax of a colon separated list of
- ! directories. The syntax of
- ! .B cdpath
- ! is that of the C shell, a blank separated list of directories.
- ! .B cdpath
- ! must be set in the environment for it to be used by
- ! .B lc.
- ! In the event that both
- ! .B CDPATH
- ! and
- ! .B cdpath
- ! are specified in the environment, the value of
- ! .B CDPATH
- ! is used.
- .PP
- .B lc
- has incorporated the minimal the spell checking routines found in the book,
- ***************
- *** 58,64 ****
- option is supplied in the environment or on the command line all
- non-directory files are ignored. If no file or directory is specified the
- current working directory is listed by default. The special entries
- ! ``.'' and ``..'' are not listed.
- .PP
- Not all options are supported on every system. (e.g. no symbolic links
- on your system ? Options
- --- 81,87 ----
- option is supplied in the environment or on the command line all
- non-directory files are ignored. If no file or directory is specified the
- current working directory is listed by default. The special entries
- ! ``.'' and ``..'' are never listed.
- .PP
- Not all options are supported on every system. (e.g. no symbolic links
- on your system ? Options
- ***************
- *** 95,101 ****
- List directories only.
- .IP "-D"
- Do not display singular files. If you do not use this option and
- ! execute "lc /unix", your output will be "/unix: file". This is
- useful in shell scripts but is sometimes annoying if you execute
- a command such as "lc /usr/lib/*" and all you wish to see is the
- first level of directories and not a lot of "filename: file" messages.
- --- 118,124 ----
- List directories only.
- .IP "-D"
- Do not display singular files. If you do not use this option and
- ! execute "lc /vmunix", your output will be "/vmunix: file". This is
- useful in shell scripts but is sometimes annoying if you execute
- a command such as "lc /usr/lib/*" and all you wish to see is the
- first level of directories and not a lot of "filename: file" messages.
- ***************
- *** 142,156 ****
- Display those files which are inaccessible. All directories will be
- displayed, thereby allowing the user to see unavailable files inside the
- directories.
- ! .SH DIAGNOSTICS
- .PP
- .B lc
- does not support recursion but I have never found this to
- be that necessary to put in.
- ! .nr
- ! $ find directory-to-descend -type d -print | xargs lc
- ! .nf
- ! works just fine when recursion is needed.
- .SH AUTHOR
- Kent Landfield <kent@sterling.com>
- .SH CREDITS
- --- 165,180 ----
- Display those files which are inaccessible. All directories will be
- displayed, thereby allowing the user to see unavailable files inside the
- directories.
- ! .SH GENERAL
- .PP
- .B lc
- does not support recursion but I have never found this to
- be that necessary to put in.
- ! .IP "$ find directory-to-descend -type d -print | xargs lc"
- ! .PP
- ! works just fine when recursion is needed. If you only wish to
- ! see one level down in the current directory structure try the following.
- ! .IP "$ lc -D *"
- .SH AUTHOR
- Kent Landfield <kent@sterling.com>
- .SH CREDITS
- diff -rc ../lc.p1/lc.c ./lc.c
- *** ../lc.p1/lc.c Sun Oct 18 17:04:02 1992
- --- ./lc.c Sun Oct 18 21:15:08 1992
- ***************
- *** 62,68 ****
- ** on your system ? Options -s, -L or -l won't be available..)
- **
- */
- ! static char *sccsid = "@(#)lc.c 1.35 8/20/92 Kent Landfield";
- #include "patchlevel.h"
-
- #include <stdio.h>
- --- 62,68 ----
- ** on your system ? Options -s, -L or -l won't be available..)
- **
- */
- ! static char *sccsid = "@(#)lc.c 1.37 10/18/92 Kent Landfield";
- #include "patchlevel.h"
-
- #include <stdio.h>
- ***************
- *** 114,122 ****
- #endif
-
- #define BUFSIZE PATH_MAX
-
- - #define NODES_PER_HUNK 256
- -
- #define TRUE 1
- #define FALSE 0
-
- --- 114,122 ----
- #endif
-
- #define BUFSIZE PATH_MAX
- + #define NODES_PER_HUNK 256
- + #define DEFAULT_SCREEN_WIDTH 80
-
- #define TRUE 1
- #define FALSE 0
-
- ***************
- *** 249,267 ****
- char *Progname;
-
- int Allfiles = FALSE; /* display '.' files as well */
- ! int Display_single = TRUE;
- int Executables = FALSE; /* mark executable files */
- int Level = 0;
- int Maxlen = 0; /* longest filename in category */
- int Only = FALSE; /* limit display to types */
- - int Screen_width = 80; /* display width 80/132 */
- int Single = FALSE; /* display files one per line */
- ! int Sort_wanted = TRUE;
- ! int Sort_down = FALSE; /* sort by columns */
- ! int Display_inode = FALSE; /* inode/file size */
- ! int Display_size = FALSE; /* inode/file size */
- ! int Sort_offset = 0; /* inode/file size */
- ! int Display_accessable = 0; /* accessable files */
-
- #define ACCESSABLE_ONLY 1
- #define INACCESSABLE_ONLY 2
- --- 249,267 ----
- char *Progname;
-
- int Allfiles = FALSE; /* display '.' files as well */
- ! int Display_accessable = 0; /* display accessable files */
- ! int Display_inode = FALSE; /* Display inode number */
- ! int Display_size = FALSE; /* Display file size */
- ! int Display_single = TRUE; /* Display on file at a time */
- int Executables = FALSE; /* mark executable files */
- int Level = 0;
- int Maxlen = 0; /* longest filename in category */
- int Only = FALSE; /* limit display to types */
- int Single = FALSE; /* display files one per line */
- ! int Sort_wanted = TRUE; /* display in directory order ? */
- ! int Sort_down = FALSE; /* sort by columns */
- ! int Sort_offset = 0;
- ! int Screen_width; /* display Screen width */
-
- #define ACCESSABLE_ONLY 1
- #define INACCESSABLE_ONLY 2
- ***************
- *** 1264,1269 ****
- --- 1264,1300 ----
- return;
- }
-
- +
- + /* G E T _ W I N _ C O L S
- + *
- + * Get the number of columns in the current window.
- + */
- +
- + int get_win_cols()
- + {
- + int co = 0;
- + #ifdef TCAP
- + char *term;
- + char entree[1024];
- +
- + if ((term = getenv("TERM")) == NULL)
- + return(0);
- +
- + switch (tgetent(entree, term)) {
- + case -1: /* "Cannot open termcap database." */
- + return(0);
- + case 0: /* "Cannot find %s in termcap database." */
- + return(0);
- + }
- + if ((co = tgetnum("co")) == -1) {
- + /* "Cannot find number of columns. " */
- + return(0);
- + }
- + #endif TCAP
- + return (co);
- + }
- +
- +
- /* S E T _ E N V _ V A R S
- *
- * set_env_vars() is used get the environment variables that
- ***************
- *** 1277,1288 ****
- {
- char *ep;
-
- ! if ((ep = getenv("COLS")) != (char *) NULL) {
- ! if (sscanf(ep, "%d", &Screen_width) == 0
- ! || (Screen_width != 80 && Screen_width != 132))
- ! Screen_width = 80;
- }
- -
- if ((ep = getenv("LC")) != (char *) NULL) {
- while (*ep != '\0') {
- valid_opt(*ep, FALSE);
- --- 1308,1322 ----
- {
- char *ep;
-
- ! if ((Screen_width = get_win_cols()) == 0) {
- ! if ((ep = getenv("COLS")) != (char *) NULL) {
- ! if (sscanf(ep, "%d", &Screen_width) == 0
- ! || (Screen_width != 80 && Screen_width != 132))
- ! Screen_width = DEFAULT_SCREEN_WIDTH;
- ! }
- ! else
- ! Screen_width = DEFAULT_SCREEN_WIDTH;
- }
- if ((ep = getenv("LC")) != (char *) NULL) {
- while (*ep != '\0') {
- valid_opt(*ep, FALSE);
- ***************
- *** 1289,1295 ****
- ep++;
- }
- }
- -
- return;
- }
-
- --- 1323,1328 ----
- ***************
- *** 1452,1460 ****
-
- /* I N _ C D P A T H
- *
- ! * in_cdpath() searches the CDPATH stored in the environment
- ! * for the filename specified. If it is found, fill the
- ! * storage area refered to by buffer with the corrected path.
- * Return TRUE if located and FALSE if not located in the CDPATH.
- */
-
- --- 1485,1495 ----
-
- /* I N _ C D P A T H
- *
- ! * in_cdpath() searches $CDPATH variable stored in the sh/ksh/zsh environments
- ! * and searches $cdpath variable in the csh environment for the filename
- ! * specified. If the filename is found, fill the storage area refered to
- ! * by buffer with the corrected path.
- ! *
- * Return TRUE if located and FALSE if not located in the CDPATH.
- */
-
- ***************
- *** 1464,1469 ****
- --- 1499,1505 ----
- int check_spelling;
- {
- static char *cdpath;
- + static char cdsep;
- static int first = 1;
-
- char *cp;
- ***************
- *** 1472,1483 ****
- int quit;
-
- if (first) {
- ! if ((cdpath = getenv("CDPATH")) != (char *) NULL)
- cdpath = str_sav(cdpath);
- first = 0;
- }
-
- ! if (cdpath == (char *) NULL)
- return (0);
-
- (void) strcpy(patbuf, cdpath);
- --- 1508,1531 ----
- int quit;
-
- if (first) {
- ! if ((cdpath = getenv("CDPATH")) != (char *) NULL) {
- cdpath = str_sav(cdpath);
- + cdsep = ':';
- + }
- + if (cdpath == (char *) NULL || *cdpath == '\0') {
- + /*
- + ** No sh $CDPATH, check if csh cdpath defined.
- + */
- + if ((cdpath = getenv("cdpath")) != (char *) NULL) {
- + cdpath = str_sav(cdpath);
- + cdsep = ' ';
- + }
- + }
- first = 0;
- }
-
- !
- ! if (cdpath == (char *) NULL || *cdpath == '\0')
- return (0);
-
- (void) strcpy(patbuf, cdpath);
- ***************
- *** 1486,1493 ****
- quit = 0;
-
- while (!quit) {
- ! cp = strchr(path, ':');
- ! if (cp == (char *) NULL)
- quit++;
- else
- *cp = '\0';
- --- 1534,1540 ----
- quit = 0;
-
- while (!quit) {
- ! if ((cp = strchr(path, cdsep)) == (char *) NULL)
- quit++;
- else
- *cp = '\0';
- ***************
- *** 1501,1519 ****
- if (access(buffer, 0) == 0)
- return (TRUE);
-
- ! if (check_spelling)
- ! {
- char bfr[BUFSIZ + 1];
- (void) strcpy(bfr, buffer);
- if (spname(bfr, buffer) == 1)
- return (TRUE);
- }
- -
- path = ++cp;
- }
- return (FALSE);
- }
- -
-
- /* M A I N
- *
- --- 1548,1563 ----
- if (access(buffer, 0) == 0)
- return (TRUE);
-
- ! if (check_spelling) {
- char bfr[BUFSIZ + 1];
- (void) strcpy(bfr, buffer);
- if (spname(bfr, buffer) == 1)
- return (TRUE);
- }
- path = ++cp;
- }
- return (FALSE);
- }
-
- /* M A I N
- *
- diff -rc ../lc.p1/lc.mk ./lc.mk
- *** ../lc.p1/lc.mk Sun Oct 18 17:04:03 1992
- --- ./lc.mk Sun Oct 18 21:15:07 1992
- ***************
- *** 1,5 ****
- #
- ! # "@(#)lc.mk 1.11 8/20/92
- #
- # Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990,
- # 1991, 1992 by Kent Landfield.
- --- 1,5 ----
- #
- ! # "@(#)lc.mk 1.13 10/18/92
- #
- # Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990,
- # 1991, 1992 by Kent Landfield.
- ***************
- *** 52,58 ****
- # or
- #
- # If you are running System V or AIX 2.2:
- ! # FLAGS = -DLENS
- # or
- #
- # This runs on AIX but it does not lint well due to the include
- --- 52,58 ----
- # or
- #
- # If you are running System V or AIX 2.2:
- ! # FLAGS = -DSYSV
- # or
- #
- # This runs on AIX but it does not lint well due to the include
- ***************
- *** 71,82 ****
- #OPTIM=-O -Wall
- OPTIM=-O
-
- # Are the directory routines in another library ?
- # Or do you wish to use shared libraries ?
- # Add additional libraries here...
- ! # LDFLAGS = -lndir
- ! # LDFLAGS = -lc_s
- ! LDFLAGS =
-
- #
- # 'qsort' function in C library
- --- 71,91 ----
- #OPTIM=-O -Wall
- OPTIM=-O
-
- + # If you wish to have LC to automagically adjust to the window size,
- + # you need to define TCAP and specify the Termcap library containing
- + # the tgetent() and tgetnum() routines.
- + #
- + TCAP=-DTCAP
- + #TERMLIB=-ltermcap
- + #TERMLIB=-lcurses
- + TERMLIB=-ltermlib
- +
- # Are the directory routines in another library ?
- # Or do you wish to use shared libraries ?
- # Add additional libraries here...
- ! # LIBS = -lndir
- ! # LIBS = -lc_s
- ! LIBS =
-
- #
- # 'qsort' function in C library
- ***************
- *** 102,113 ****
- # it matters...
- #
- BINDIR=/bin
- MODE=755
- OWNER=bin
- GROUP=bin
-
- ! CFLAGS = $(OPTIM) $(FLAGS) $(BLKSIZE) $(RPTSIZ) $(LENGTH)
- ! LINTFLAGS = $(FLAGS) $(BLKSIZE) $(RPTSIZ) $(LENGTH)
- SRCS = lc.c $(QSORTC)
- OBJS = lc.o $(QSORTO)
-
- --- 111,125 ----
- # it matters...
- #
- BINDIR=/bin
- + MANDIR=/usr/local/man/man1
- + MANEXT=1
- MODE=755
- OWNER=bin
- GROUP=bin
- + LDFLAGS = $(TERMLIB) $(LIBS)
-
- ! CFLAGS = $(OPTIM) $(FLAGS) $(BLKSIZE) $(RPTSIZ) $(LENGTH) $(TCAP)
- ! LINTFLAGS = $(FLAGS) $(BLKSIZE) $(RPTSIZ) $(LENGTH) $(TCAP)
- SRCS = lc.c $(QSORTC)
- OBJS = lc.o $(QSORTO)
-
- ***************
- *** 123,134 ****
- clobber: clean
- rm -f lc
-
- ! install: lc
- strip lc
- cp lc $(BINDIR)/lc
- chmod $(MODE) $(BINDIR)/lc
- chown $(OWNER) $(BINDIR)/lc
- chgrp $(GROUP) $(BINDIR)/lc
-
- print:
- cprint MANIFEST | lpr -Plw
- --- 135,154 ----
- clobber: clean
- rm -f lc
-
- ! install: lc
- strip lc
- cp lc $(BINDIR)/lc
- chmod $(MODE) $(BINDIR)/lc
- chown $(OWNER) $(BINDIR)/lc
- chgrp $(GROUP) $(BINDIR)/lc
- +
- + man: $(MANDIR)/lc.$(MANEXT)
- +
- + $(MANDIR)/lc.$(MANEXT): lc.1
- + cp lc.1 $(MANDIR)/lc.$(MANEXT)
- + chmod 444 $(MANDIR)/lc.$(MANEXT)
- + chown $(OWNER) $(MANDIR)/lc.$(MANEXT)
- + chgrp $(GROUP) $(MANDIR)/lc.$(MANEXT)
-
- print:
- cprint MANIFEST | lpr -Plw
- diff -rc ../lc.p1/patchlevel.h ./patchlevel.h
- *** ../lc.p1/patchlevel.h Sun Oct 18 17:04:03 1992
- --- ./patchlevel.h Sun Oct 18 21:15:07 1992
- ***************
- *** 1,5 ****
- /*
- ! ** @(#)patchlevel.h 1.2 8/19/92
- */
- #define RELEASE 2
- ! #define PATCHLEVEL 1
- --- 1,5 ----
- /*
- ! ** @(#)patchlevel.h 1.3 10/18/92
- */
- #define RELEASE 2
- ! #define PATCHLEVEL 2
- exit 0 # Just in case...
-