home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume31 / lc / part01 < prev    next >
Encoding:
Text File  |  1992-08-13  |  29.9 KB  |  908 lines

  1. Newsgroups: comp.sources.misc
  2. From: kent@sparky.sterling.com (Kent Landfield)
  3. Subject:  v31i072:  lc - Categorize and List Files In Columns, Part01/02
  4. Message-ID: <csm-v31i072=lc.131250@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 0557e8d2ae9abd3288cf9f2a29dccd86
  6. Date: Fri, 7 Aug 1992 18:27:49 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: kent@sparky.sterling.com (Kent Landfield)
  10. Posting-number: Volume 31, Issue 72
  11. Archive-name: lc/part01
  12. Environment: UNIX, AmigaDOS, MINIX, Coherent
  13. Supersedes: lc: Volume 14, Issue 82-83
  14.  
  15. lc is much like the ls command except it separates the types of files into 
  16. groups and then displays located filenames to the user is a columnar fashion. 
  17.  
  18. lc has incorporated minimal spell checking for people who's fingers like to 
  19. transpose characters regularly like mine...
  20.  
  21. lc uses three different environment variables COLS, CDPATH, and LC allowing 
  22. you to customize how you wish lc to perform on a default basis. 
  23.  
  24. lc uses CDPATH to locate files that are requested but are not in the specified 
  25. location or within the local directory. This feature greatly reduces full path
  26. typing just to see the contents of a directory.
  27.  
  28. COLS is used to switch the column width between 80 and 132 column displays.
  29.  
  30. LC is used to set lc specific options. The options can be specified using LC 
  31. or supplied on the command line.  Command line supplied options override 
  32. options specified in the LC environment variable.
  33.  
  34.  lc -- categorize files in a directory and list column-wise
  35.  
  36.    Usage:       lc [ options ] [ directory ... ]
  37.  
  38.    Options:
  39.         -a      List dot files as well
  40.         -b      List block special files only
  41.         -B      Display the size in blocks
  42.         -c      List character special files only
  43.         -C      Sort down the columns instead of across
  44.         -d      List directories only
  45.         -D      Do not display singular files
  46.         -e      Mark executable files with '*'
  47.         -f      List regular files only
  48.         -F      List fifo files only
  49.         -i      Display the inode number
  50.         -I      Suppress unresolved symbolic link messages
  51.         -l      Mark symbolic links with '@'
  52.         -L      Display symbolic links
  53.         -m      List shared memory name space entry files only
  54.         -M      List semaphore name space entry files only
  55.         -r      Do not sort the filenames before displaying
  56.         -s      List symbolic links only
  57.         -S      List socket file only
  58.         -v      Print the version of lc 
  59.         -x      Only display those files the user owns or has access to
  60.         -X      Only display those files the user does not own and does 
  61.                 not have access to
  62.         -1      List files one per line instead of in columns
  63.  
  64.    The "only" options can be combined.
  65.  
  66. If there is no 'directory' specified, the current directory is used.
  67.  
  68. Not all options are supported on every system. (e.g. no symbolic links on 
  69. your system ? Options -s, -I -L or -l won't be available..) If your system 
  70. does not support shared memory name space entry files, then you cannot use 
  71. the -m option...
  72.  
  73. I'd like to publically thank those who helped improve lc during this
  74. release.  Thanks all!!!
  75.  
  76.     Jonathan Bayer  <jbayer@ispi.com>
  77.     Tim Goodwin     <Tim.Goodwin@uknet.ac.uk>
  78.     Rick Ohnemus    <rick@sparky.imd.sterling.com>
  79.     Tom Rushworth   <uunet!tfic.bc.ca!tbr>
  80.  
  81. I have had requests for lc on a Cray YMP/el.   Would anyone care to port lc 
  82. to the Cray ?  I will gladly incorporate the changes.  Sorry but I don't have 
  83. access to a Cray at the moment...
  84.  
  85.             -Kent+
  86. ----
  87. #! /bin/sh
  88. # This is a shell archive.  Remove anything before this line, then feed it
  89. # into a shell via "sh file" or similar.  To overwrite existing files,
  90. # type "sh file -c".
  91. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  92. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  93. # Contents:  README MANIFEST History lc.1 lc.mk patchlevel.h qsort.c
  94. # Wrapped by kent@sparky on Fri Aug  7 12:44:03 1992
  95. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  96. echo If this archive is complete, you will see the following message:
  97. echo '          "shar: End of archive 1 (of 2)."'
  98. if test -f 'README' -a "${1}" != "-c" ; then 
  99.   echo shar: Will not clobber existing file \"'README'\"
  100. else
  101.   echo shar: Extracting \"'README'\" \(4997 characters\)
  102.   sed "s/^X//" >'README' <<'END_OF_FILE'
  103. X
  104. X            LC
  105. X
  106. X                "@(#)README    1.8 8/7/92 Kent Landfield"
  107. X
  108. XThis directory contains the source to lc. lc is much like the ls 
  109. Xcommand except it separates the types of files into groups and then
  110. Xdisplays located file names to the user is a columnar fashion. 
  111. X
  112. X"lc"'s history goes back to 1978 when it was originally developed at the
  113. XUniversity of Waterloo on a Honeywell 66/60 system. It became so popular 
  114. Xthat it was ported to Waterloo's V7 Unix systems shortly thereafter.  
  115. XThis version is a complete re-implementation of lc and contains no 
  116. XUniversity of Waterloo code.
  117. X
  118. XThis version of lc was initially implemented by myself after I became 
  119. Xaccustomed to the lc command on a Mark Williams Coherent system I was 
  120. Xrunning back in 1984.  When I started moving to different systems I 
  121. Xfound that I did not like the lack of information, flexibility and the 
  122. Xgeneral display that ls provided.  I have found that I am not the only 
  123. Xone that has become fed up with ls and its jumbled output. All the 
  124. Xpeople here use lc much more than they use ls. It is a locally well 
  125. Xknown fact that when a new machine comes into the house, the first local 
  126. Xsoftware that is put on the machine is lc.  It is far from perfect but 
  127. Xit is better than ls on a general use basis. 
  128. X
  129. Xlc uses three different environment variables COLS, CDPATH, and LC
  130. Xallowing you to customize how you wish lc to perform on a default 
  131. Xbasis. COLS is used to switch the column width between 80 and 132 
  132. Xcolumn display.  LC is used to set lc specific options. The command 
  133. Xline options shown in the option list below are available to be used 
  134. Xin setting up how lc is to work for you. Options that you supply on 
  135. Xthe command line override options that are specified in the environment.
  136. Xlc uses CDPATH to locate files that are requested but are not in the 
  137. Xspecified location or within the local directory.
  138. X
  139. Xlc has incorporated minimal spell checking using slightly modified
  140. Xroutines found in the book, The UNIX Programming Environment, by 
  141. XBrian Kernighan and Rob Pike.
  142. X
  143. XThe following is a quick reference of options to lc. These options
  144. Xcan be specified in the Environment variable LC so that they are
  145. Xdone each time lc is executed.
  146. X
  147. X lc -- categorize files in a directory and list column-wise
  148. X
  149. X   Usage:       lc [ options ] [ directory ... ]
  150. X
  151. X   Options:
  152. X        -a      List dot files as well.
  153. X        -b      List block special files only
  154. X        -B      Display the size in blocks
  155. X        -c      List character special files only
  156. X        -C      Sort down the columns instead of across
  157. X        -d      List directories only
  158. X        -D      Do not display singular files
  159. X        -e      Mark executable files with '*'
  160. X        -f      List regular files only
  161. X        -F      List fifo files only
  162. X        -i      Display the inode number
  163. X        -I      Suppress unresolved symbolic link messages.
  164. X        -l      Mark symbolic links with '@'
  165. X        -L      Display symbolic links
  166. X        -m      List shared memory name space entry files only
  167. X        -M      List semaphore name space entry files only
  168. X        -r      Do not sort the filenames before displaying.
  169. X        -s      List symbolic links only
  170. X        -S      List socket file only
  171. X        -v      Print the version of lc 
  172. X        -x      Only display those files the user owns or has access to.
  173. X        -X      Only display those files the user does not own and does 
  174. X                not have access to.
  175. X        -1      List files one per line instead of in columns.
  176. X
  177. X  
  178. X   The "only" options can be combined.
  179. X
  180. X   If there is no 'directory' specified, the current directory is used.
  181. X
  182. X   Not all options are supported on every system. (e.g. no symbolic links
  183. X   on your system ? Options -s, -I -L or -l won't be available..)
  184. X   If your system does not support shared memory name space entry files, 
  185. X   then you cannot use the -m option...
  186. X
  187. XThe following is a todo list that may get done someday...
  188. X
  189. X1. Port to all flavors of unix on all platforms. Lofty goal but
  190. X   on-going... :-)
  191. X                                                        
  192. X                          *PLEASE!* 
  193. X
  194. XIf you have a problem, there's someone else out there who either has
  195. Xhad or will have the same problem.  Please send all "lc" ideas, patches, 
  196. Xetc to 
  197. X
  198. XINTERNET: kent@Sterling.COM or UUCP: uunet!sparky!kent
  199. X
  200. Xso that I can continue to improve the functionality and portability of lc.
  201. X
  202. XJust a note for historical interest: David Tanguay of Software Development 
  203. XGroup, University of Waterloo informs me that LC stands for "list catalog".
  204. XGCOS TSS on the Honeywell used the term "catalog", meaning (roughly) the
  205. Xsame thing as a Unix directory. The GCOS file system maintenance program
  206. Xwas called ACCE (short for access), a Swiss Army knife type program, and
  207. Xone of its sub-functions was LC, which gave the usual baroque display.
  208. XA separate LC program was written to give the more commonly wanted structure
  209. Xinfo, and CLIS (for catalog listing) to give a more "ls -l" type of display.
  210. X
  211. X            -Kent+
  212. X
  213. X    
  214. END_OF_FILE
  215.   if test 4997 -ne `wc -c <'README'`; then
  216.     echo shar: \"'README'\" unpacked with wrong size!
  217.   fi
  218.   # end of 'README'
  219. fi
  220. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  221.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  222. else
  223.   echo shar: Extracting \"'MANIFEST'\" \(554 characters\)
  224.   sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  225. X   File Name        Archive #    Description
  226. X----------------------------------------------------------
  227. X README                     1    General information file.
  228. X MANIFEST                   1    This shipping list.
  229. X History                    1   The history of lc.
  230. X lc.1                       2    lc manual page in nroff format.
  231. X lc.c                       1    Source to the lc command.
  232. X lc.mk                      1    Makefile for the lc command.
  233. X patchlevel.h               1   Patch level indicator file.
  234. X qsort.c                    1    BSD libc.a qsort source (optional)
  235. END_OF_FILE
  236.   if test 554 -ne `wc -c <'MANIFEST'`; then
  237.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  238.   fi
  239.   # end of 'MANIFEST'
  240. fi
  241. if test -f 'History' -a "${1}" != "-c" ; then 
  242.   echo shar: Will not clobber existing file \"'History'\"
  243. else
  244.   echo shar: Extracting \"'History'\" \(1992 characters\)
  245.   sed "s/^X//" >'History' <<'END_OF_FILE'
  246. X#
  247. X# @(#)History    1.2 8/6/92
  248. X#
  249. X#  This file is a running history of the lc command.
  250. X#
  251. X#  This file is not meant to describe every system that lc runs on
  252. X#  just those that were important at the time.
  253. X#
  254. XHistory:
  255. X      1984:
  256. X      =====
  257. X      Initially designed on an IBM-XT running Coherent in 1984.
  258. X      Ported to XENIX on an IBM-AT.
  259. X
  260. X      1985:
  261. X      =====
  262. X      Ported to System V on AT&T 3Bs in 1985.
  263. X
  264. X      1986:
  265. X      =====
  266. X      Ported to DEC Vax 11/750 running System V.
  267. X      Ported to BSD4.2 on a Sequent Balance 8000.
  268. X      Jeff Minnig added the initial support for links.  Good Job Jeff!
  269. X
  270. X      1988:
  271. X      =====
  272. X      Ported to SunOS 4.0 on a Sun 3/60.
  273. X      Rick Ohnemus did major surgery to remove static storage
  274. X      and *greatly* enhanced the link support. Thanks Rick!
  275. X
  276. X      1989:
  277. X      =====
  278. X      Tested with Ultrix 3.0 & 3.1 on a DECstation 3100.
  279. X      Tested with Ultrix 3.0 & 3.1 on a VAXstation 3500.
  280. X      Ported to AIX 2.2 on an IBM RT.
  281. X      Tested with UTek on a Tektronix 4319.
  282. X      Tested with IRIX System V on a Silicon Graphics Iris 4D/210GTX.
  283. X      Tested with AmigaDOS 1.3 on an Amiga 1000.
  284. X      Tested with SunOS 4.0.3 on a Sparkstation 1.
  285. X      Tested with UTek on a Tektronix XD8810.
  286. X
  287. X      1990:
  288. X      =====
  289. X      Tested with AIX 3.+ on a Risc System/6000.
  290. X      Ivan Fris added the ability to combine "only" options.
  291. X      Mike Peterson ported it to the Apollo Domain/OS SR10.2.
  292. X
  293. X      1992:
  294. X      =====
  295. X      - Tim Goodwin fixed a bug concerning unresolved symbolic links which
  296. X        were specified on the command line.
  297. X  
  298. X      - Jonthan Bayer added the ability to display block sizes with the files,
  299. X          added the ability to display inodes with the files,
  300. X          added the ability to sort the files by column,
  301. X          added the ability to display file which are inaccessible,
  302. X          added the ability to display only those files accessible by the user,
  303. X          added spell checking to the CDPATH.  Fantastic additions Jonathan!!
  304. END_OF_FILE
  305.   if test 1992 -ne `wc -c <'History'`; then
  306.     echo shar: \"'History'\" unpacked with wrong size!
  307.   fi
  308.   # end of 'History'
  309. fi
  310. if test -f 'lc.1' -a "${1}" != "-c" ; then 
  311.   echo shar: Will not clobber existing file \"'lc.1'\"
  312. else
  313.   echo shar: Extracting \"'lc.1'\" \(5907 characters\)
  314.   sed "s/^X//" >'lc.1' <<'END_OF_FILE'
  315. X.\" @(#)lc.1    1.7 8/7/92 Kent Landfield;
  316. X.TH LC 1 "Usenet Source"
  317. X.SH NAME
  318. X.B lc 
  319. X\- categorize and list directory and file names in columns
  320. X.SH SYNOPSIS
  321. X.B lc
  322. X[
  323. X.B \-abBcCdDefFiIlLmMrsS1xX
  324. X]
  325. X[ directory ... ]
  326. X.SH DESCRIPTION
  327. X.B lc
  328. Xlists the elements of the given directories.  The elements are
  329. Xdivided into minimally five basic types (files, directories, 
  330. Xcharacter special files, block special files, and fifos) and 
  331. Xare printed in alphabetical order.  They are normally printed 
  332. Xcolumn-wise across the screen, preceded by a title indicating
  333. Xthe type. The
  334. X.B \-1
  335. Xoption can be used to force single-column untitled output, and the
  336. X.B \-C
  337. Xoption can be used to print column-wise down the screen.
  338. X.PP
  339. X.B lc
  340. Xuses the environment variables
  341. X.B LC,
  342. X.B CDPATH 
  343. Xand
  344. X.B COLS 
  345. Xto allow you to set up a default set of display options that
  346. X.B lc
  347. Xshould use each time is it run. Options on the command line override
  348. Xoptions specified in the environment if there is a conflict.
  349. X.B LC
  350. Xis used to set 
  351. X.B lc
  352. Xspecific options. All command line options shown in the option list 
  353. Xbelow can be used in setting default options within the environment 
  354. Xvariable 
  355. X.B LC.
  356. X.B CDPATH 
  357. Xis searched for a file not found at the requested location or
  358. Xin the current directory. This is an extremely handy feature of 
  359. X.B lc.
  360. X.B COLS 
  361. Xis used to switch the column width between 80 and 132 column display.
  362. X.PP
  363. X.B lc 
  364. Xhas incorporated the minimal the spell checking routines found in the book,
  365. XThe UNIX Programming Environment, by Brian Kernighan and Rob Pike.  
  366. X.PP
  367. XIf the command line argument list contains more than one name, the 
  368. Xcontents of the directories named in the list are displayed and all 
  369. Xother names are displayed one per line with the type of the file 
  370. Xdisplayed on the same line. If the 
  371. X.B -D 
  372. Xoption is supplied in the environment or on the command line all 
  373. Xnon-directory files are ignored.  If no file or directory is specified the 
  374. Xcurrent working directory is listed by default.  The special entries
  375. X``.'' and ``..'' are not listed.
  376. X.PP
  377. XNot all options are supported on every system. (e.g. no symbolic links
  378. Xon your system ? Options 
  379. X.B -s, -I -L
  380. Xor 
  381. X.B -l
  382. Xwon't be available...) On systems which support symbolic links, 
  383. Xthe symbolic links are normally followed, and each prints under 
  384. Xthe category of the type of file to which it is linked.  If the 
  385. Xsymbolic link points to a nonexistent path name, or if you do not 
  386. Xhave permission to resolve the path name,
  387. X.B lc
  388. Xprints out an error message indicating it cannot resolve the link.
  389. XThis type of message can be suppressed through the use of the 
  390. X.B 'I'
  391. Xoption described below.
  392. X.SH OPTIONS
  393. X.IP "-a" 6
  394. XList dot files as well. Normally 
  395. X.B lc 
  396. Xdoes not display files beginning with a '.' unless this option is 
  397. Xspecified. The system '.' and '.. files are never displayed since
  398. Xthey give you no real additional information and would just clutter
  399. Xup the display.
  400. X.IP "-b"
  401. XList block special files only.
  402. X.IP "-B"
  403. XDisplay the file size in blocks along with the file name.
  404. X.IP "-c"
  405. XList character special files only.
  406. X.IP "-C"
  407. XSort by column.
  408. X.IP "-d"
  409. XList directories only.
  410. X.IP "-D"
  411. XDo not display singular files. If you do not use this option and
  412. Xexecute "lc /unix", your output will be "/unix: file". This is 
  413. Xuseful in shell scripts but is sometimes annoying if you execute
  414. Xa command such as "lc /usr/lib/*" and all you wish to see is the
  415. Xfirst level of directories and not a lot of "filename: file" messages.
  416. X.IP "-e"
  417. XMark executable files with '*'. This options allows you to have executables
  418. Xdisplayed with a '*' appended to the end of the file name.
  419. X.IP "-f"
  420. XList regular files only.
  421. X.IP "-F"
  422. XList fifo files only.
  423. X.IP "-i"
  424. XDisplay the inode number along with the file name.
  425. X.IP "-I"
  426. XDo not report unresolved symbolic link messages. Normally
  427. X.B lc
  428. Xprints out a message stating that it cannot resolve the symbolic link.
  429. XUse of this option suppresses the display of those messages.
  430. X.IP "-l"
  431. XMark symbolic links with '@'. This options allows you to have symbolic
  432. Xlinks displayed with a '@' appended to the end of the file name.
  433. X.IP "-L"
  434. XDisplay symbolic links. This options allows you to have 
  435. X.B lc
  436. Xoutput a display showing what files the symbolic links refer to.
  437. X.IP "-m"
  438. XList shared memory name space entry files only.
  439. X.IP "-M"
  440. XList semaphore name space entry files only.
  441. X.IP "-r"
  442. XList the directory entries as they appear in the directory file. No 
  443. Xsorting of output prior to displaying.
  444. X.IP "-s"
  445. XList symbolic links only.
  446. X.IP "-S"
  447. XList AF_UNIX socket files only.
  448. X.IP "-1"
  449. XList files one per line instead of in columns.
  450. X.IP "-v"
  451. XPrint the software's version information.
  452. X.IP "-x"
  453. XOnly display those files and directories which are either owned by the user or
  454. Xaccessible by the user.
  455. X.IP "-X"
  456. XDisplay those files which are inaccessible.  All directories will be
  457. Xdisplayed, thereby allowing the user to see unavailable files inside the
  458. Xdirectories.
  459. X.SH DIAGNOSTICS
  460. X.PP
  461. X.B lc
  462. Xdoes not support recursion but I have never found this to
  463. Xbe that necessary to put in. 
  464. X.nr
  465. X      $ find directory-to-descend -type d -print | xargs lc
  466. X.nf
  467. Xworks just fine when recursion is needed.
  468. X.SH AUTHOR
  469. XKent Landfield <kent@sterling.com>
  470. X.SH CREDITS
  471. X.nr
  472. XJeff Minnig <jeff@dsndata.uucp> added the initial symbolic link support and
  473. Xported lc to run in both domains on Sequent's Balance 8000.
  474. X.PP
  475. XRick Ohnemus <rick@IMD.Sterling.COM> did major surgery to remove static 
  476. Xstorage and *greatly* enhanced the link support. Thanks Rick!
  477. X.PP
  478. XMike Peterson <root@alchemy.chem.utoronto.ca> ported lc to the Apollo Domain/OS SR10.2.
  479. X.PP
  480. XIvan Fris <neumann.une.oz.au!ivan> added the ability to combine the "only" options.
  481. X.PP
  482. XTim Goodwin <Tim.Goodwin@uknet.ac.uk> fixed a bug concerning unresolved 
  483. Xsymbolic links specified on the command line. 
  484. X.PP
  485. XJonathan Bayer <jbayer@ispi.com> added several features, including the 
  486. Xoptions -C -i -x -X and added spell checking to CDPATH usage.  Thanks Jonathan!
  487. END_OF_FILE
  488.   if test 5907 -ne `wc -c <'lc.1'`; then
  489.     echo shar: \"'lc.1'\" unpacked with wrong size!
  490.   fi
  491.   # end of 'lc.1'
  492. fi
  493. if test -f 'lc.mk' -a "${1}" != "-c" ; then 
  494.   echo shar: Will not clobber existing file \"'lc.mk'\"
  495. else
  496.   echo shar: Extracting \"'lc.mk'\" \(3185 characters\)
  497.   sed "s/^X//" >'lc.mk' <<'END_OF_FILE'
  498. X#
  499. X#    "@(#)lc.mk    1.10 8/6/92 
  500. X#
  501. X#  Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990,
  502. X#                1991, 1992 by Kent Landfield.
  503. X#
  504. X# This makefile is used to compile lc. 
  505. X#
  506. XI =    /usr/include
  507. XS =     $(I)/sys
  508. X#
  509. X#  Have a favorite C compiler that is not cc... Too bad. ;-)
  510. XCC=cc
  511. X#CC=gcc
  512. X#
  513. X# Specify the multiple of 512 that your du(1) reports blocksizes System V 
  514. X# du(1) gives the number of 512 byte blocks while BSD specifies kilobytes.
  515. X#RPTSIZ = -DBLK_MULTIPLE=1
  516. XRPTSIZ = -DBLK_MULTIPLE=2
  517. X
  518. X# If you want to specify the block size here uncomment the following line:
  519. X#BLKSIZE = -DBLOCKSIZE=512
  520. X#
  521. X# If you are running on a BSD 4.2 box:
  522. X# (note - if compiling on a sequent in att environment...`ucb make -f lc.mk`)
  523. X# FLAGS = -DBSD -DDIRECT
  524. X#         or
  525. X#
  526. X# If you are running on a BSD (4.3 or later), SunOS (4.0 or later),
  527. X# or Ultrix (3.0 or later) box:
  528. XFLAGS = -DBSD -DLENS
  529. X#
  530. X# FLAGS = -DBSD
  531. X#         or
  532. X#
  533. X# If you are running on an Ultrix box and using the POSIX environment:
  534. X# FLAGS = -DPOSIX
  535. X#         or
  536. X#
  537. X# If you are running on a Xenix box:
  538. X# FLAGS = -DXENIX
  539. X#         or
  540. X#
  541. X# If you are running System V or AIX 2.2:
  542. X# FLAGS =  -DLENS
  543. X#         or
  544. X#
  545. X# This runs on AIX but it does not lint well due to the include
  546. X# files on AIX. It works, that's all I can say...
  547. X# If you are running AIX 3.0 or later:
  548. X# FLAGS = -D_BSD -DBSD
  549. X#         or
  550. X#
  551. X# If you are running System V with Doug Gwyn's directory routines
  552. X# or Silicon Graphics or Utek 3.2d:
  553. X# FLAGS = -DPOSIX
  554. X# 
  555. X#
  556. X# OPTIM is used for setting debugging or optimizing
  557. X# flags for the compilation.
  558. X#OPTIM=-O -Wall
  559. XOPTIM=-O
  560. X
  561. X# Are the directory routines in another library ?
  562. X# Or do you wish to use shared libraries ?
  563. X# Add additional libraries here...
  564. X# LDFLAGS = -lndir
  565. X# LDFLAGS = -lc_s
  566. XLDFLAGS = 
  567. X#
  568. X# 'qsort' function in C library
  569. X# QSORTO =
  570. X# QSORTC =
  571. X#
  572. X# 'qsort' function not in C library Or Your qsort library
  573. X# function is slooow.
  574. X#
  575. X# QSORTO = qsort.o
  576. X# QSORTC = qsort.c
  577. X#
  578. X# Installation ownership and directory. Customize
  579. X# for your installation. Warning, if you do not
  580. X# install this on your root partition, it will
  581. X# not be available for use in single user mode.
  582. X# Yes I know that this last statement is obvious
  583. X# but it is extremely irritating not to have it
  584. X# available...
  585. X#
  586. X# This is one program that we use so often, that we have set
  587. X# the sticky bit on (chmod +t lc) on our older systems were
  588. X# it matters...
  589. X#
  590. XBINDIR=/bin
  591. XMODE=755
  592. XOWNER=bin
  593. XGROUP=bin
  594. X
  595. XCFLAGS = $(OPTIM) $(FLAGS) $(BLKSIZE) $(RPTSIZ)
  596. XLINTFLAGS = $(FLAGS) $(BLKSIZE) $(RPTSIZ)
  597. XSRCS = lc.c $(QSORTC)
  598. XOBJS = lc.o $(QSORTO)
  599. X
  600. Xlc: lc.o $(QSORTO)
  601. X    $(CC) $(CFLAGS) lc.o $(QSORTO) -o lc $(LDFLAGS)
  602. X
  603. Xlint:
  604. X    lint $(LINTFLAGS) $(SRCS)
  605. X
  606. Xclean:
  607. X    rm -f $(OBJS)
  608. X
  609. Xclobber: clean
  610. X    rm -f lc
  611. X
  612. Xinstall: lc
  613. X    strip lc
  614. X    cp lc $(BINDIR)/lc
  615. X    chmod $(MODE)  $(BINDIR)/lc
  616. X    chown $(OWNER) $(BINDIR)/lc
  617. X    chgrp $(GROUP) $(BINDIR)/lc
  618. X
  619. Xprint:
  620. X    cprint MANIFEST  | lpr -Plw
  621. X    cprint README    | lpr -Plw
  622. X    cprint lc.1      | lpr -Plw
  623. X    cprint lc.c      | lpr -Plw
  624. X    cprint lc.mk     | lpr -Plw
  625. X    cprint qsort.c   | lpr -Plw
  626. X
  627. X# CodeCenter lines
  628. X
  629. Xlc_src: $(SRCS)
  630. X    #load $(CFLAGS) $(SRCS)
  631. X
  632. X# Purify lines
  633. X
  634. Xpurify: lc.o $(QSORTO)
  635. X    purify $(CC) $(CFLAGS) lc.o $(QSORTO) -o lc $(LDFLAGS)
  636. X
  637. END_OF_FILE
  638.   if test 3185 -ne `wc -c <'lc.mk'`; then
  639.     echo shar: \"'lc.mk'\" unpacked with wrong size!
  640.   fi
  641.   # end of 'lc.mk'
  642. fi
  643. if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  644.   echo shar: Will not clobber existing file \"'patchlevel.h'\"
  645. else
  646.   echo shar: Extracting \"'patchlevel.h'\" \(79 characters\)
  647.   sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
  648. X/*
  649. X**    @(#)patchlevel.h    1.1 8/2/92
  650. X*/
  651. X#define RELEASE 2
  652. X#define PATCHLEVEL 0
  653. END_OF_FILE
  654.   if test 79 -ne `wc -c <'patchlevel.h'`; then
  655.     echo shar: \"'patchlevel.h'\" unpacked with wrong size!
  656.   fi
  657.   # end of 'patchlevel.h'
  658. fi
  659. if test -f 'qsort.c' -a "${1}" != "-c" ; then 
  660.   echo shar: Will not clobber existing file \"'qsort.c'\"
  661. else
  662.   echo shar: Extracting \"'qsort.c'\" \(6230 characters\)
  663.   sed "s/^X//" >'qsort.c' <<'END_OF_FILE'
  664. X/*
  665. X * Copyright (c) 1980 Regents of the University of California.
  666. X * All rights reserved.
  667. X *
  668. X * Redistribution and use in source and binary forms are permitted
  669. X * provided that the above copyright notice and this paragraph are
  670. X * duplicated in all such forms and that any documentation,
  671. X * advertising materials, and other materials related to such
  672. X * distribution and use acknowledge that the software was developed
  673. X * by the University of California, Berkeley.  The name of the
  674. X * University may not be used to endorse or promote products derived
  675. X * from this software without specific prior written permission.
  676. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  677. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  678. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  679. X */
  680. X
  681. X#if !defined(lint)
  682. Xstatic char sccsid[] = "@(#)qsort.c    5.4 (Berkeley) 6/27/88";
  683. X#endif /* LIBC_SCCS and not lint */
  684. X
  685. X/*
  686. X * qsort.c:
  687. X * Our own version of the system qsort routine which is faster by an average
  688. X * of 25%, with lows and highs of 10% and 50%.
  689. X * The THRESHold below is the insertion sort threshold, and has been adjusted
  690. X * for records of size 48 bytes.
  691. X * The MTHREShold is where we stop finding a better median.
  692. X */
  693. X
  694. X#define        THRESH        4        /* threshold for insertion */
  695. X#define        MTHRESH        6        /* threshold for median */
  696. X
  697. Xstatic  int        (*qcmp)();        /* the comparison routine */
  698. Xstatic  int        qsz;            /* size of each record */
  699. Xstatic  int        thresh;            /* THRESHold in chars */
  700. Xstatic  int        mthresh;        /* MTHRESHold in chars */
  701. X
  702. X/*
  703. X * qst:
  704. X * Do a quicksort
  705. X * First, find the median element, and put that one in the first place as the
  706. X * discriminator.  (This "median" is just the median of the first, last and
  707. X * middle elements).  (Using this median instead of the first element is a big
  708. X * win).  Then, the usual partitioning/swapping, followed by moving the
  709. X * discriminator into the right place.  Then, figure out the sizes of the two
  710. X * partions, do the smaller one recursively and the larger one via a repeat of
  711. X * this code.  Stopping when there are less than THRESH elements in a partition
  712. X * and cleaning up with an insertion sort (in our caller) is a huge win.
  713. X * All data swaps are done in-line, which is space-losing but time-saving.
  714. X * (And there are only three places where this is done).
  715. X */
  716. X
  717. Xstatic void
  718. Xqst(base, max)
  719. X    char *base, *max;
  720. X{
  721. X    register char c, *i, *j, *jj;
  722. X    register int ii;
  723. X    char *mid, *tmp;
  724. X    int lo, hi;
  725. X
  726. X    /*
  727. X     * At the top here, lo is the number of characters of elements in the
  728. X     * current partition.  (Which should be max - base).
  729. X     * Find the median of the first, last, and middle element and make
  730. X     * that the middle element.  Set j to largest of first and middle.
  731. X     * If max is larger than that guy, then it's that guy, else compare
  732. X     * max with loser of first and take larger.  Things are set up to
  733. X     * prefer the middle, then the first in case of ties.
  734. X     */
  735. X    lo = max - base;        /* number of elements as chars */
  736. X    do    {
  737. X        mid = i = base + qsz * ((lo / qsz) >> 1);
  738. X        if (lo >= mthresh) {
  739. X            j = (qcmp((jj = base), i) > 0 ? jj : i);
  740. X            if (qcmp(j, (tmp = max - qsz)) > 0) {
  741. X                /* switch to first loser */
  742. X                j = (j == jj ? i : jj);
  743. X                if (qcmp(j, tmp) < 0)
  744. X                    j = tmp;
  745. X            }
  746. X            if (j != i) {
  747. X                ii = qsz;
  748. X                do    {
  749. X                    c = *i;
  750. X                    *i++ = *j;
  751. X                    *j++ = c;
  752. X                } while (--ii);
  753. X            }
  754. X        }
  755. X        /*
  756. X         * Semi-standard quicksort partitioning/swapping
  757. X         */
  758. X        for (i = base, j = max - qsz; ; ) {
  759. X            while (i < mid && qcmp(i, mid) <= 0)
  760. X                i += qsz;
  761. X            while (j > mid) {
  762. X                if (qcmp(mid, j) <= 0) {
  763. X                    j -= qsz;
  764. X                    continue;
  765. X                }
  766. X                tmp = i + qsz;    /* value of i after swap */
  767. X                if (i == mid) {
  768. X                    /* j <-> mid, new mid is j */
  769. X                    mid = jj = j;
  770. X                } else {
  771. X                    /* i <-> j */
  772. X                    jj = j;
  773. X                    j -= qsz;
  774. X                }
  775. X                goto swap;
  776. X            }
  777. X            if (i == mid) {
  778. X                break;
  779. X            } else {
  780. X                /* i <-> mid, new mid is i */
  781. X                jj = mid;
  782. X                tmp = mid = i;    /* value of i after swap */
  783. X                j -= qsz;
  784. X            }
  785. X        swap:
  786. X            ii = qsz;
  787. X            do    {
  788. X                c = *i;
  789. X                *i++ = *jj;
  790. X                *jj++ = c;
  791. X            } while (--ii);
  792. X            i = tmp;
  793. X        }
  794. X        /*
  795. X         * Look at sizes of the two partitions, do the smaller
  796. X         * one first by recursion, then do the larger one by
  797. X         * making sure lo is its size, base and max are update
  798. X         * correctly, and branching back.  But only repeat
  799. X         * (recursively or by branching) if the partition is
  800. X         * of at least size THRESH.
  801. X         */
  802. X        i = (j = mid) + qsz;
  803. X        if ((lo = j - base) <= (hi = max - i)) {
  804. X            if (lo >= thresh)
  805. X                qst(base, j);
  806. X            base = i;
  807. X            lo = hi;
  808. X        } else {
  809. X            if (hi >= thresh)
  810. X                qst(i, max);
  811. X            max = j;
  812. X        }
  813. X    } while (lo >= thresh);
  814. X    return;
  815. X}
  816. X
  817. X/*
  818. X * qsort:
  819. X * First, set up some global parameters for qst to share.  Then, quicksort
  820. X * with qst(), and then a cleanup insertion sort ourselves.  Sound simple?
  821. X * It's not...
  822. X */
  823. X
  824. Xvoid
  825. Xqsort(base, n, size, compar)
  826. X    char    *base;
  827. X    int    n;
  828. X    int    size;
  829. X    int    (*compar)();
  830. X{
  831. X    register char c, *i, *j, *lo, *hi;
  832. X    char *min, *max;
  833. X
  834. X    if (n <= 1)
  835. X        return;
  836. X    qsz = size;
  837. X    qcmp = compar;
  838. X    thresh = qsz * THRESH;
  839. X    mthresh = qsz * MTHRESH;
  840. X    max = base + n * qsz;
  841. X    if (n >= THRESH) {
  842. X        qst(base, max);
  843. X        hi = base + thresh;
  844. X    } else {
  845. X        hi = max;
  846. X    }
  847. X    /*
  848. X     * First put smallest element, which must be in the first THRESH, in
  849. X     * the first position as a sentinel.  This is done just by searching
  850. X     * the first THRESH elements (or the first n if n < THRESH), finding
  851. X     * the min, and swapping it into the first position.
  852. X     */
  853. X    for (j = lo = base; (lo += qsz) < hi; )
  854. X        if (qcmp(j, lo) > 0)
  855. X            j = lo;
  856. X    if (j != base) {
  857. X        /* swap j into place */
  858. X        for (i = base, hi = base + qsz; i < hi; ) {
  859. X            c = *j;
  860. X            *j++ = *i;
  861. X            *i++ = c;
  862. X        }
  863. X    }
  864. X    /*
  865. X     * With our sentinel in place, we now run the following hyper-fast
  866. X     * insertion sort.  For each remaining element, min, from [1] to [n-1],
  867. X     * set hi to the index of the element AFTER which this one goes.
  868. X     * Then, do the standard insertion sort shift on a character at a time
  869. X     * basis for each element in the frob.
  870. X     */
  871. X    for (min = base; (hi = min += qsz) < max; ) {
  872. X        while (qcmp(hi -= qsz, min) > 0)
  873. X            /* void */;
  874. X        if ((hi += qsz) != min) {
  875. X            for (lo = min + qsz; --lo >= min; ) {
  876. X                c = *lo;
  877. X                for (i = j = lo; (j -= qsz) >= hi; i = j)
  878. X                    *i = *j;
  879. X                *i = c;
  880. X            }
  881. X        }
  882. X    }
  883. X    return;
  884. X}
  885. END_OF_FILE
  886.   if test 6230 -ne `wc -c <'qsort.c'`; then
  887.     echo shar: \"'qsort.c'\" unpacked with wrong size!
  888.   fi
  889.   # end of 'qsort.c'
  890. fi
  891. echo shar: End of archive 1 \(of 2\).
  892. cp /dev/null ark1isdone
  893. MISSING=""
  894. for I in 1 2 ; do
  895.     if test ! -f ark${I}isdone ; then
  896.     MISSING="${MISSING} ${I}"
  897.     fi
  898. done
  899. if test "${MISSING}" = "" ; then
  900.     echo You have unpacked both archives.
  901.     rm -f ark[1-9]isdone
  902. else
  903.     echo You still must unpack the following archives:
  904.     echo "        " ${MISSING}
  905. fi
  906. exit 0
  907. exit 0 # Just in case...
  908.