home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume39 / lc / patch02 next >
Encoding:
Text File  |  1993-08-30  |  16.9 KB  |  634 lines

  1. Newsgroups: comp.sources.misc
  2. From: kent@sparky.sterling.com (Kent Landfield)
  3. Subject: v39i067:  lc - Categorize and List Files In Columns, Patch02
  4. Message-ID: <1993Aug30.120931.22445@sparky.sterling.com>
  5. X-Md4-Signature: 10fe89d587fd2a1817d212c558904282
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Mon, 30 Aug 1993 12:09:31 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: kent@sparky.sterling.com (Kent Landfield)
  12. Posting-number: Volume 39, Issue 67
  13. Archive-name: lc/patch02
  14. Environment: UNIX, AmigaDOS, MINIX, Coherent, Cray, OSF/1
  15. Patch-To: lc: Volume 31, Issue 72-73
  16.  
  17. This is the second patch to lc.  This patch contains elements of creeping
  18. featurism... :-)  
  19.  
  20.    o Adds the ability for lc to automagically determine the width of the
  21.      display screen.
  22.      
  23.    o Adds support for the Cshell cdpath variable which behaves like the 
  24.      existing CDPATH functionality.
  25.  
  26. Also, lc has been ported to OSF/1 using GCC.  Anyone want to try putting it 
  27. on BSDI or Linux ?  If you do please let me know as I do not have access
  28. to those systems currently.  Thanks.
  29.  
  30.             -Kent+
  31. ----
  32. diff -rc ../lc.p1/lc.1 ./lc.1
  33. *** ../lc.p1/lc.1    Sun Oct 18 17:04:02 1992
  34. --- ./lc.1    Sun Oct 18 21:15:08 1992
  35. ***************
  36. *** 1,4 ****
  37. ! .\" @(#)lc.1    1.8 8/20/92 Kent Landfield;
  38.   .TH LC 1 "Usenet Source"
  39.   .SH NAME
  40.   .B lc 
  41. --- 1,4 ----
  42. ! .\" @(#)lc.1    1.10 10/18/92 Kent Landfield;
  43.   .TH LC 1 "Usenet Source"
  44.   .SH NAME
  45.   .B lc 
  46. ***************
  47. *** 25,37 ****
  48.   .B lc
  49.   uses the environment variables
  50.   .B LC,
  51. ! .B CDPATH 
  52.   and
  53. ! .B COLS 
  54. ! to allow you to set up a default set of display options that
  55.   .B lc
  56. ! should use each time is it run. Options on the command line override
  57. ! options specified in the environment if there is a conflict.
  58.   .B LC
  59.   is used to set 
  60.   .B lc
  61. --- 25,38 ----
  62.   .B lc
  63.   uses the environment variables
  64.   .B LC,
  65. ! .B CDPATH,
  66.   and
  67. ! .B cdpath
  68. ! to allow you to set up default display options which are used by
  69.   .B lc
  70. ! each time is it run. Options on the command line override
  71. ! options specified in the environment if there is a conflict. The
  72. ! environment variable 
  73.   .B LC
  74.   is used to set 
  75.   .B lc
  76. ***************
  77. *** 39,50 ****
  78.   below can be used in setting default options within the environment 
  79.   variable 
  80.   .B LC.
  81. ! .B CDPATH 
  82. ! is searched for a file not found at the requested location or
  83. ! in the current directory. This is an extremely handy feature of 
  84. ! .B lc.
  85.   .B COLS 
  86. ! is used to switch the column width between 80 and 132 column display.
  87.   .PP
  88.   .B lc 
  89.   has incorporated the minimal the spell checking routines found in the book,
  90. --- 40,73 ----
  91.   below can be used in setting default options within the environment 
  92.   variable 
  93.   .B LC.
  94. ! Depending on how its compiled,
  95. ! .B lc
  96. ! determines the screen width automagically.  If your version was not compiled to use 
  97. ! termcap library routines, the environment variable
  98.   .B COLS 
  99. ! is used to set the screen width.  
  100. ! .B CDPATH
  101. ! and
  102. ! .B cdpath 
  103. ! are searched for a file or directory not found at the requested location or
  104. ! within the current directory. This is an extremely handy feature of 
  105. ! .B lc.
  106. ! The valid format of 
  107. ! .B CDPATH
  108. ! is that of the standard Bourne/Korn shell syntax of a colon separated list of 
  109. ! directories.  The syntax of 
  110. ! .B cdpath
  111. ! is that of the C shell, a blank separated list of directories.
  112. ! .B cdpath 
  113. ! must be set in the environment for it to be used by
  114. ! .B lc.
  115. ! In the event that both 
  116. ! .B CDPATH
  117. ! and 
  118. ! .B cdpath 
  119. ! are specified in the environment, the value of 
  120. ! .B CDPATH 
  121. ! is used.
  122.   .PP
  123.   .B lc 
  124.   has incorporated the minimal the spell checking routines found in the book,
  125. ***************
  126. *** 58,64 ****
  127.   option is supplied in the environment or on the command line all 
  128.   non-directory files are ignored.  If no file or directory is specified the 
  129.   current working directory is listed by default.  The special entries
  130. ! ``.'' and ``..'' are not listed.
  131.   .PP
  132.   Not all options are supported on every system. (e.g. no symbolic links
  133.   on your system ? Options 
  134. --- 81,87 ----
  135.   option is supplied in the environment or on the command line all 
  136.   non-directory files are ignored.  If no file or directory is specified the 
  137.   current working directory is listed by default.  The special entries
  138. ! ``.'' and ``..'' are never listed.
  139.   .PP
  140.   Not all options are supported on every system. (e.g. no symbolic links
  141.   on your system ? Options 
  142. ***************
  143. *** 95,101 ****
  144.   List directories only.
  145.   .IP "-D"
  146.   Do not display singular files. If you do not use this option and
  147. ! execute "lc /unix", your output will be "/unix: file". This is 
  148.   useful in shell scripts but is sometimes annoying if you execute
  149.   a command such as "lc /usr/lib/*" and all you wish to see is the
  150.   first level of directories and not a lot of "filename: file" messages.
  151. --- 118,124 ----
  152.   List directories only.
  153.   .IP "-D"
  154.   Do not display singular files. If you do not use this option and
  155. ! execute "lc /vmunix", your output will be "/vmunix: file". This is 
  156.   useful in shell scripts but is sometimes annoying if you execute
  157.   a command such as "lc /usr/lib/*" and all you wish to see is the
  158.   first level of directories and not a lot of "filename: file" messages.
  159. ***************
  160. *** 142,156 ****
  161.   Display those files which are inaccessible.  All directories will be
  162.   displayed, thereby allowing the user to see unavailable files inside the
  163.   directories.
  164. ! .SH DIAGNOSTICS
  165.   .PP
  166.   .B lc
  167.   does not support recursion but I have never found this to
  168.   be that necessary to put in. 
  169. ! .nr
  170. !       $ find directory-to-descend -type d -print | xargs lc
  171. ! .nf
  172. ! works just fine when recursion is needed.
  173.   .SH AUTHOR
  174.   Kent Landfield <kent@sterling.com>
  175.   .SH CREDITS
  176. --- 165,180 ----
  177.   Display those files which are inaccessible.  All directories will be
  178.   displayed, thereby allowing the user to see unavailable files inside the
  179.   directories.
  180. ! .SH GENERAL
  181.   .PP
  182.   .B lc
  183.   does not support recursion but I have never found this to
  184.   be that necessary to put in. 
  185. ! .IP "$ find directory-to-descend -type d -print | xargs lc"
  186. ! .PP
  187. ! works just fine when recursion is needed.  If you only wish to 
  188. ! see one level down in the current directory structure try the following.
  189. ! .IP "$ lc -D *"
  190.   .SH AUTHOR
  191.   Kent Landfield <kent@sterling.com>
  192.   .SH CREDITS
  193. diff -rc ../lc.p1/lc.c ./lc.c
  194. *** ../lc.p1/lc.c    Sun Oct 18 17:04:02 1992
  195. --- ./lc.c    Sun Oct 18 21:15:08 1992
  196. ***************
  197. *** 62,68 ****
  198.   ** on your system ? Options -s, -L or -l won't be available..)
  199.   **
  200.   */
  201. ! static char *sccsid = "@(#)lc.c    1.35 8/20/92 Kent Landfield";
  202.   #include "patchlevel.h"
  203.   
  204.   #include <stdio.h>
  205. --- 62,68 ----
  206.   ** on your system ? Options -s, -L or -l won't be available..)
  207.   **
  208.   */
  209. ! static char *sccsid = "@(#)lc.c    1.37 10/18/92 Kent Landfield";
  210.   #include "patchlevel.h"
  211.   
  212.   #include <stdio.h>
  213. ***************
  214. *** 114,122 ****
  215.   #endif
  216.   
  217.   #define BUFSIZE         PATH_MAX
  218.   
  219. - #define NODES_PER_HUNK  256
  220.   #define TRUE            1
  221.   #define FALSE           0
  222.   
  223. --- 114,122 ----
  224.   #endif
  225.   
  226.   #define BUFSIZE         PATH_MAX
  227. + #define NODES_PER_HUNK       256
  228. + #define DEFAULT_SCREEN_WIDTH  80
  229.   
  230.   #define TRUE            1
  231.   #define FALSE           0
  232.   
  233. ***************
  234. *** 249,267 ****
  235.   char *Progname;
  236.   
  237.   int Allfiles = FALSE;       /* display '.' files as well    */
  238. ! int Display_single = TRUE;  
  239.   int Executables = FALSE;    /* mark executable files        */
  240.   int Level = 0;              
  241.   int Maxlen = 0;             /* longest filename in category */
  242.   int Only = FALSE;           /* limit display to types       */
  243. - int Screen_width = 80;      /* display width 80/132         */
  244.   int Single = FALSE;         /* display files one per line   */
  245. ! int Sort_wanted = TRUE;
  246. ! int Sort_down = FALSE;      /* sort by columns */
  247. ! int Display_inode = FALSE;  /* inode/file size */
  248. ! int Display_size = FALSE;   /* inode/file size */
  249. ! int Sort_offset = 0;        /* inode/file size */
  250. ! int Display_accessable = 0; /* accessable files */
  251.   
  252.   #define ACCESSABLE_ONLY    1
  253.   #define INACCESSABLE_ONLY  2
  254. --- 249,267 ----
  255.   char *Progname;
  256.   
  257.   int Allfiles = FALSE;       /* display '.' files as well    */
  258. ! int Display_accessable = 0; /* display accessable files     */
  259. ! int Display_inode = FALSE;  /* Display inode number         */
  260. ! int Display_size = FALSE;   /* Display file size            */
  261. ! int Display_single = TRUE;  /* Display on file at a time    */
  262.   int Executables = FALSE;    /* mark executable files        */
  263.   int Level = 0;              
  264.   int Maxlen = 0;             /* longest filename in category */
  265.   int Only = FALSE;           /* limit display to types       */
  266.   int Single = FALSE;         /* display files one per line   */
  267. ! int Sort_wanted = TRUE;     /* display in directory order ? */
  268. ! int Sort_down = FALSE;      /* sort by columns              */
  269. ! int Sort_offset = 0;        
  270. ! int Screen_width;           /* display Screen width         */
  271.   
  272.   #define ACCESSABLE_ONLY    1
  273.   #define INACCESSABLE_ONLY  2
  274. ***************
  275. *** 1264,1269 ****
  276. --- 1264,1300 ----
  277.       return;
  278.   }
  279.   
  280. + /* G E T _ W I N _ C O L S 
  281. +  *  
  282. +  * Get the number of columns in the current window.
  283. +  */ 
  284. +  
  285. + int get_win_cols() 
  286. + {
  287. +     int co = 0;
  288. + #ifdef TCAP
  289. +     char *term;
  290. +     char entree[1024];
  291. +   
  292. +     if ((term = getenv("TERM")) == NULL) 
  293. +         return(0);
  294. +   
  295. +     switch (tgetent(entree, term)) {
  296. +        case -1: /* "Cannot open termcap database." */
  297. +            return(0);
  298. +        case 0: /* "Cannot find %s in termcap database." */
  299. +            return(0);
  300. +     }
  301. +     if ((co = tgetnum("co")) == -1) {
  302. +        /* "Cannot find number of columns. " */
  303. +        return(0);
  304. +     }
  305. + #endif TCAP
  306. +     return (co);
  307. + }
  308.   /* S E T _ E N V _ V A R S
  309.    *
  310.    * set_env_vars() is used get the environment variables that
  311. ***************
  312. *** 1277,1288 ****
  313.   {
  314.       char *ep;
  315.   
  316. !     if ((ep = getenv("COLS")) != (char *) NULL) {
  317. !         if (sscanf(ep, "%d", &Screen_width) == 0
  318. !             || (Screen_width != 80 && Screen_width != 132))
  319. !             Screen_width = 80;
  320.       }
  321.       if ((ep = getenv("LC")) != (char *) NULL) {
  322.           while (*ep != '\0') {
  323.               valid_opt(*ep, FALSE);
  324. --- 1308,1322 ----
  325.   {
  326.       char *ep;
  327.   
  328. !     if ((Screen_width = get_win_cols()) == 0) {
  329. !         if ((ep = getenv("COLS")) != (char *) NULL) {
  330. !            if (sscanf(ep, "%d", &Screen_width) == 0
  331. !                || (Screen_width != 80 && Screen_width != 132))
  332. !                Screen_width = DEFAULT_SCREEN_WIDTH;
  333. !         }
  334. !         else
  335. !            Screen_width = DEFAULT_SCREEN_WIDTH;
  336.       }
  337.       if ((ep = getenv("LC")) != (char *) NULL) {
  338.           while (*ep != '\0') {
  339.               valid_opt(*ep, FALSE);
  340. ***************
  341. *** 1289,1295 ****
  342.               ep++;
  343.           }
  344.       }
  345.       return;
  346.   }
  347.   
  348. --- 1323,1328 ----
  349. ***************
  350. *** 1452,1460 ****
  351.   
  352.   /*  I N _ C D P A T H
  353.    *
  354. !  *  in_cdpath() searches the CDPATH stored in the environment
  355. !  *  for the filename specified. If it is found, fill the
  356. !  *  storage area refered to by buffer with the corrected path.
  357.    *  Return TRUE if located and FALSE if not located in the CDPATH.
  358.    */
  359.    
  360. --- 1485,1495 ----
  361.   
  362.   /*  I N _ C D P A T H
  363.    *
  364. !  *  in_cdpath() searches $CDPATH variable stored in the sh/ksh/zsh environments
  365. !  *  and searches $cdpath variable in the csh environment for the filename 
  366. !  *  specified. If the filename is found, fill the storage area refered to 
  367. !  *  by buffer with the corrected path.
  368. !  *
  369.    *  Return TRUE if located and FALSE if not located in the CDPATH.
  370.    */
  371.    
  372. ***************
  373. *** 1464,1469 ****
  374. --- 1499,1505 ----
  375.       int  check_spelling; 
  376.   {
  377.       static char *cdpath;
  378. +     static char cdsep;
  379.       static int first = 1;
  380.   
  381.       char *cp;
  382. ***************
  383. *** 1472,1483 ****
  384.       int quit;
  385.   
  386.       if (first) {
  387. !         if ((cdpath = getenv("CDPATH")) != (char *) NULL)
  388.               cdpath = str_sav(cdpath);
  389.           first = 0;
  390.       }   
  391.   
  392. !     if (cdpath == (char *) NULL)
  393.           return (0);
  394.   
  395.       (void) strcpy(patbuf, cdpath);
  396. --- 1508,1531 ----
  397.       int quit;
  398.   
  399.       if (first) {
  400. !         if ((cdpath = getenv("CDPATH")) != (char *) NULL) {
  401.               cdpath = str_sav(cdpath);
  402. +             cdsep = ':';
  403. +         }
  404. +         if (cdpath == (char *) NULL || *cdpath == '\0') {
  405. +             /*
  406. +             ** No sh $CDPATH, check if csh cdpath defined.
  407. +             */
  408. +             if ((cdpath = getenv("cdpath")) != (char *) NULL) {
  409. +                 cdpath = str_sav(cdpath);
  410. +                 cdsep = ' ';
  411. +             }
  412. +         }
  413.           first = 0;
  414.       }   
  415.   
  416. !     if (cdpath == (char *) NULL || *cdpath == '\0') 
  417.           return (0);
  418.   
  419.       (void) strcpy(patbuf, cdpath);
  420. ***************
  421. *** 1486,1493 ****
  422.       quit = 0;
  423.   
  424.       while (!quit) {
  425. !         cp = strchr(path, ':');
  426. !         if (cp == (char *) NULL)
  427.               quit++;
  428.           else
  429.               *cp = '\0';
  430. --- 1534,1540 ----
  431.       quit = 0;
  432.   
  433.       while (!quit) {
  434. !         if ((cp = strchr(path, cdsep)) == (char *) NULL)
  435.               quit++;
  436.           else
  437.               *cp = '\0';
  438. ***************
  439. *** 1501,1519 ****
  440.           if (access(buffer, 0) == 0)
  441.               return (TRUE);
  442.    
  443. !         if (check_spelling)
  444. !         {
  445.               char bfr[BUFSIZ + 1];
  446.               (void) strcpy(bfr, buffer);
  447.               if (spname(bfr, buffer) == 1)
  448.                   return (TRUE);
  449.           }
  450. -         
  451.           path = ++cp;
  452.       }
  453.       return (FALSE);
  454.   }
  455.   
  456.   /*  M A I N 
  457.    * 
  458. --- 1548,1563 ----
  459.           if (access(buffer, 0) == 0)
  460.               return (TRUE);
  461.    
  462. !         if (check_spelling) {
  463.               char bfr[BUFSIZ + 1];
  464.               (void) strcpy(bfr, buffer);
  465.               if (spname(bfr, buffer) == 1)
  466.                   return (TRUE);
  467.           }
  468.           path = ++cp;
  469.       }
  470.       return (FALSE);
  471.   }
  472.   
  473.   /*  M A I N 
  474.    * 
  475. diff -rc ../lc.p1/lc.mk ./lc.mk
  476. *** ../lc.p1/lc.mk    Sun Oct 18 17:04:03 1992
  477. --- ./lc.mk    Sun Oct 18 21:15:07 1992
  478. ***************
  479. *** 1,5 ****
  480.   #
  481. ! #    "@(#)lc.mk    1.11 8/20/92 
  482.   #
  483.   #  Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990,
  484.   #                1991, 1992 by Kent Landfield.
  485. --- 1,5 ----
  486.   #
  487. ! #    "@(#)lc.mk    1.13 10/18/92 
  488.   #
  489.   #  Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990,
  490.   #                1991, 1992 by Kent Landfield.
  491. ***************
  492. *** 52,58 ****
  493.   #         or
  494.   #
  495.   # If you are running System V or AIX 2.2:
  496. ! # FLAGS =  -DLENS
  497.   #         or
  498.   #
  499.   # This runs on AIX but it does not lint well due to the include
  500. --- 52,58 ----
  501.   #         or
  502.   #
  503.   # If you are running System V or AIX 2.2:
  504. ! # FLAGS =  -DSYSV
  505.   #         or
  506.   #
  507.   # This runs on AIX but it does not lint well due to the include
  508. ***************
  509. *** 71,82 ****
  510.   #OPTIM=-O -Wall
  511.   OPTIM=-O
  512.   
  513.   # Are the directory routines in another library ?
  514.   # Or do you wish to use shared libraries ?
  515.   # Add additional libraries here...
  516. ! # LDFLAGS = -lndir
  517. ! # LDFLAGS = -lc_s
  518. ! LDFLAGS = 
  519.   
  520.   #
  521.   # 'qsort' function in C library
  522. --- 71,91 ----
  523.   #OPTIM=-O -Wall
  524.   OPTIM=-O
  525.   
  526. + # If you wish to have LC to automagically adjust to the window size,
  527. + # you need to define TCAP and specify the Termcap library containing 
  528. + # the tgetent() and tgetnum() routines.
  529. + #
  530. + TCAP=-DTCAP
  531. + #TERMLIB=-ltermcap
  532. + #TERMLIB=-lcurses
  533. + TERMLIB=-ltermlib
  534.   # Are the directory routines in another library ?
  535.   # Or do you wish to use shared libraries ?
  536.   # Add additional libraries here...
  537. ! # LIBS = -lndir
  538. ! # LIBS = -lc_s
  539. ! LIBS =
  540.   
  541.   #
  542.   # 'qsort' function in C library
  543. ***************
  544. *** 102,113 ****
  545.   # it matters...
  546.   #
  547.   BINDIR=/bin
  548.   MODE=755
  549.   OWNER=bin
  550.   GROUP=bin
  551.   
  552. ! CFLAGS = $(OPTIM) $(FLAGS) $(BLKSIZE) $(RPTSIZ) $(LENGTH)
  553. ! LINTFLAGS = $(FLAGS) $(BLKSIZE) $(RPTSIZ) $(LENGTH)
  554.   SRCS = lc.c $(QSORTC)
  555.   OBJS = lc.o $(QSORTO)
  556.   
  557. --- 111,125 ----
  558.   # it matters...
  559.   #
  560.   BINDIR=/bin
  561. + MANDIR=/usr/local/man/man1
  562. + MANEXT=1
  563.   MODE=755
  564.   OWNER=bin
  565.   GROUP=bin
  566. + LDFLAGS = $(TERMLIB) $(LIBS)
  567.   
  568. ! CFLAGS = $(OPTIM) $(FLAGS) $(BLKSIZE) $(RPTSIZ) $(LENGTH) $(TCAP)
  569. ! LINTFLAGS = $(FLAGS) $(BLKSIZE) $(RPTSIZ) $(LENGTH) $(TCAP)
  570.   SRCS = lc.c $(QSORTC)
  571.   OBJS = lc.o $(QSORTO)
  572.   
  573. ***************
  574. *** 123,134 ****
  575.   clobber: clean
  576.       rm -f lc
  577.   
  578. ! install: lc
  579.       strip lc
  580.       cp lc $(BINDIR)/lc
  581.       chmod $(MODE)  $(BINDIR)/lc
  582.       chown $(OWNER) $(BINDIR)/lc
  583.       chgrp $(GROUP) $(BINDIR)/lc
  584.   
  585.   print:
  586.       cprint MANIFEST  | lpr -Plw
  587. --- 135,154 ----
  588.   clobber: clean
  589.       rm -f lc
  590.   
  591. ! install: lc 
  592.       strip lc
  593.       cp lc $(BINDIR)/lc
  594.       chmod $(MODE)  $(BINDIR)/lc
  595.       chown $(OWNER) $(BINDIR)/lc
  596.       chgrp $(GROUP) $(BINDIR)/lc
  597. + man: $(MANDIR)/lc.$(MANEXT)
  598. + $(MANDIR)/lc.$(MANEXT):    lc.1
  599. +     cp lc.1 $(MANDIR)/lc.$(MANEXT)
  600. +     chmod 444 $(MANDIR)/lc.$(MANEXT)
  601. +     chown $(OWNER) $(MANDIR)/lc.$(MANEXT)
  602. +     chgrp $(GROUP) $(MANDIR)/lc.$(MANEXT)
  603.   
  604.   print:
  605.       cprint MANIFEST  | lpr -Plw
  606. diff -rc ../lc.p1/patchlevel.h ./patchlevel.h
  607. *** ../lc.p1/patchlevel.h    Sun Oct 18 17:04:03 1992
  608. --- ./patchlevel.h    Sun Oct 18 21:15:07 1992
  609. ***************
  610. *** 1,5 ****
  611.   /*
  612. ! **    @(#)patchlevel.h    1.2 8/19/92
  613.   */
  614.   #define RELEASE 2
  615. ! #define PATCHLEVEL 1
  616. --- 1,5 ----
  617.   /*
  618. ! **    @(#)patchlevel.h    1.3 10/18/92
  619.   */
  620.   #define RELEASE 2
  621. ! #define PATCHLEVEL 2
  622. exit 0 # Just in case...
  623.