home *** CD-ROM | disk | FTP | other *** search
- From: davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr)
- Newsgroups: alt.sources
- Subject: le, a versatile replacement for ls
- Message-ID: <2187@crdos1.crd.ge.COM>
- Date: 29 Mar 90 19:37:45 GMT
-
-
- This was rejected for publication in comp.sources.misc for reasons I
- don't totally inderstand. Anyway it's a file listing program with a
- number of options to control what characteristics are displayed, and how
- they are displayed. For example, the date changed, modified, or accessed
- may be displayed, in human readable format or as yyyy-mm-dd hh:mm:ss so
- "sort" will put things in order.
-
- I like this because the dates don't change format as the file ages,
- while ls starts including the year after a while. Awk scripts which read
- the dates get complex quickly.
-
- Original by Peter DaSilva many years ago, changes and some
- documentation by me.
-
- #!/bin/sh
- # shar: Shell Archiver (v1.27)
- #
- # Run the following text with /bin/sh to create:
- # le.doc
- # le.1
- # le.c
- #
- echo "x - extracting le.doc (Text)"
- sed 's/^X//' << 'SHAR_EOF' > le.doc &&
- XArticle 2687 (43 more) in net.sources:
- XFrom: peter@baylor.UUCP (Peter da Silva)
- XSubject: le.c
- XMessage-ID: <506@baylor.UUCP>
- XDate: 21 Aug 85 19:05:15 GMT
- XDate-Received: 28 Aug 85 08:22:21 GMT
- XDistribution: net
- XOrganization: The Power Elite, Houston, TX
- XLines: 82
- X
- Xle is an extended ls, designed to please all the people who want to get
- Xweird info on a file. It dumps reliable info in reliable positions, for
- Xexample it won't stick the major/minor device #s in the file size feild
- Xof the output. Let me see about the options...
- X
- X
- XWithout any flags it outputs the same info as ls...
- X
- X Usage: le [-A|-N] [-diMmlUuGgrsatc] [-Ttab] [-Hh] [-D] [file]...
- X
- X -d Toggle 'dev' flag.
- X -i Toggle 'inode' flag.
- X -m Toggle 'mode' flag.
- X -M Toggle 'short mode' (octal mode) flag.
- X -l Toggle 'links' flag.
- X -u Toggle 'user' flag.
- X -U Toggle 'short user' (userid) flag.
- X -g Toggle 'group' flag.
- X -G Toggle 'short group' (groupid) flag.
- X -r Toggle 'rdev' flag.
- X -s Toggle 'size' flag.
- X -k Toggle 'ksize' flag.
- X -a Toggle 'atime' flag.
- X -t Toggle 'mtime' flag.
- X -c Toggle 'ctime' flag.
- X -h Print help and exit.
- X -H Force output of the header.
- X -N (None) Clear all flags.
- X -A (All) Set all flags.
- X -D Dont list directories (like ls -d).
- X -Ttab Use the string 'tab' to seperate feilds instead of space.
- X -f Format dates so they will sort in ascending order
- X
- X The flags can be included in any order but having any of
- X[dimMluUgGrsatc] before [AN] is kind of useless, and having [Hh]
- Xbefore [dimMluUgGrsatc] can be misleading. You can intersperse
- Xoptions with files if you want to list different directories
- Xdifferently. I don't see any reason to do this but I also see no
- Xgood reason to prevent this (no, I don't use getopt).
- X
- XAs an example: here is 'ls -al' compared with 'le'
- X
- XNote that feild 7 varies between a time and a year, and that 4 varies
- Xbetween a size and a device #... while this is more useful for humans
- Xit's kind of hard on awk... le isn't a replacement for 'ls', just for
- Xls in shell scripts so you can keep awk and relatives happy.
- X
- X% ls -al /dev
- Xtotal 4
- Xc-w--w--w- 2 root 5, 0 Aug 21 13:46 aux1
- Xc-w--w--w- 2 root 5, 1 May 20 09:50 aux2
- Xcrw--w--w- 1 root 0, 8 Aug 20 13:52 console
- X...
- Xcrw-rw-rw- 1 root 1, 23 Aug 18 1982 hsix7
- Xcrw------- 1 root 2, 1 Aug 20 13:52 kmem
- X-rw-rw-r-- 1 root 1635 Jul 11 17:39 lp
- Xc-w--w--w- 2 root 5, 0 Aug 21 13:46 lp1
- Xc-w--w--w- 2 root 5, 1 May 20 09:50 lp2
- X...
- Xcrw--w--w- 1 root 0, 15 Jul 23 15:38 tty7
- X% le /dev
- Xdrwxr-xr-x 2 root 928 11 Jul 85 16:40 /dev/.
- Xdrwxr-xr-x 11 root 368 20 Aug 85 13:52 /dev/..
- Xc-w--w--w- 2 root 0 21 Aug 85 13:46 /dev/aux1
- Xc-w--w--w- 2 root 0 20 May 85 9:50 /dev/aux2
- Xcrw--w--w- 1 root 0 20 Aug 85 13:52 /dev/console
- X...
- Xcrw-rw-rw- 1 root 0 18 Aug 82 11:11 /dev/hsix7
- Xcrw------- 1 root 0 20 Aug 85 13:52 /dev/kmem
- X-rw-rw-r-- 1 root 1635 11 Jul 85 17:39 /dev/lp
- Xc-w--w--w- 2 root 0 21 Aug 85 13:46 /dev/lp1
- Xc-w--w--w- 2 root 0 20 May 85 9:50 /dev/lp2
- X...
- Xcrw--w--w- 1 root 0 23 Jul 85 15:38 /dev/tty7
- X
- XThere is a problem: le expands control characters to '^X', which may cause
- Xproblems in some cases... le -N is thus not exactly the equivalent of ls -A.
- XThis code can be easily changed if this proves a problem. Don't ask me why
- X/dev/lp is a regular file, I didn't create it... :-> Time to go do some sa-type
- Xstuff.
- X--
- X Peter (Made in Australia) da Silva
- X UUCP: ...!shell!neuro1!{hyd-ptd,baylor,datafac}!peter
- X MCI: PDASILVA; CIS: 70216,1076
- X________________________________________________________________
- X
- XNotes from bill davidsen:
- X
- XThe original version had one flag which toggled having the headers on
- Xand print the header after the options were evaluated, and another which
- Xforced the header out when parsed, sometimes before other options
- Xmodified the display format. Now -H prints the headers after all options
- Xare evaluated.
- X
- XI wanted to be able to sort the information on time modified, accessed,
- Xetc, so I added the -f option to output the date in yyyy-mm-dd format,
- Xsuch as 1988-12-08, so that 'sort' will correctly sort the output, and
- Xmy little database program will find things by date.
- X
- XI added -h as help, because I can't remember the more obscure options of
- Xthe program, I frequently don't have a manual handy, and at the time I
- Xadded help there was no man page and I may not find time to write one.
- SHAR_EOF
- chmod 0644 le.doc || echo "restore of le.doc fails"
- echo "x - extracting le.1 (Text)"
- sed 's/^X//' << 'SHAR_EOF' > le.1 &&
- X'\" @(#)skeleton 3.3 - 12/21/83
- X'\" [c][e][t] (only if preprocessing by cw, eqn, and/or tbl required)
- X.TH LE 1 local
- X'\" Heading: name(sect) center (paren) name(sect)
- X.SH NAME
- Xle - display directory infomation with format control
- X.SH SYNOPSIS
- Xle [-A|-N] [-diMmlUuGgrsatc] [-Ttab] [-Hh] [-D] [file]...
- X.SH DESCRIPTION
- X.B le
- XGives much the same information as 'ls' but does so with full user
- Xcontrol. ls makes format changes, such as having the year in the date
- Xsometimes, or putting the major and minor device numbers in place of
- Xfile size. These are excelent choices for humans, but they confuse
- X\fIsed\fR and \fIawk\fR.
- X\fBle\fR allows the user full control of the output contents, including
- Xheaders. All fields have the same format and width for all items.
- X.SS Options
- XOptions are parsed left to right, which allows options which affect the
- Xentire format to be modified by specifying exceptions, rather than by
- Xlisting all of the defaults individually.
- X.ne 10
- X.SS "Options affecting more than one field
- X.TS
- Xtab(@);
- Xlbw(.5i) l.
- X-A@T{
- XDisplay \fIall\fR information on this file. This will produce a report
- Xwider than 80 columns.
- XT}
- X
- X-N@T{
- XDisplay only the filename. Additional information may be added by use of
- Xfollowing options.
- XT}
- X
- X-h@Generate a help listing of options
- X
- X-f@T{
- XChange date format for sorting. The default format for dates is
- X.tr ~
- Xdd~mmm~yy, for human readability. The \fB-f\fR changes this to
- Xyyyy-mm-dd, which allows sorting by \fIsort\fR or other programs using
- Xan alphabetic or numeric sort.
- XT}
- X
- X-D@T{
- XDon't expand directories. Information is printed about the directory,
- Xrather than the contents of it.
- XT}
- X
- X-Tx@Separate fields by \fIx\fR instead of blanks.
- X
- X-H@Output a header describing the contents of each field.
- X.TE
- X.sp
- X.ne 10
- X.SS "Options which toggle the display of selected information
- X.TS
- Xtab(@);
- Xlbw(.5i) l.
- X-m@T{
- Xcontrols the display of mode information in alphabetic format, such as
- X"drwx--x--x" which is produced by "ls~-l".
- XT}
- X
- X-M@T{
- Xcontrols the display of "short mode" information, shown as an octal
- Xvalue such as is given by listing the contents of a \fItar\fR or
- X\fIcpio\fR dump on most systems.
- XT}
- X
- X-l@controls the display of the number of links to the inode.
- X
- X-i@controls display of the inode number.
- X
- X-d@T{
- Xcontrols display of the inode device. This is the major and minor device
- Xnumbers for the device on which the inode is stored.
- XT}
- X
- X-r@T{
- Xcontrols the display of the major and minor device numbers of cataloged
- Xdevices. This will be the same information displayed in place of the
- Xsize by "ls~-l".
- XT}
- X
- X-u@controls display of the UID by name.
- X
- X-U@controls the display of the UID by number.
- X
- X-g@controls the display of the GID by name.
- X
- X-G@controls the display of the GID by number.
- X
- X-s@controls display of the filesize in bytes.
- X
- X-k@controls display of the filesize in k.
- X
- X-a@controls display of the date last accessed.
- X
- X-c@controls display of the date the inode was last modified.
- X
- X-t@controls display of the date the file was last modofied.
- X.TE
- X.ne 15
- X.SH EXAMPLES
- X.nf
- X.in +.5i
- X\" change to constant width font or use .cs
- X.ft CW
- X$ le -Hr
- X Rdev Long mode Lnx User Size Modify time File name
- X 2,224 drwxr-xr-x 3 bin 2688 9 Nov 88 14:52 /dev/.
- X 2,232 drwxr-xr-x 17 bin 496 29 Nov 88 8:36 /dev/..
- X103, 73 drwxrwxrwx 2 root 592 10 Sep 87 14:49 /dev/EXOS
- X 8, 0 crw-r--r-- 1 root 0 5 Dec 88 18:18 /dev/clock
- X 7, 0 crw-r--r-- 1 sysinfo 0 30 May 86 17:52 /dev/cmos
- X 0, 0 crw-rw-rw- 1 root 0 8 Dec 88 9:45 /dev/console
- X 1, 47 brw------- 1 sysinfo 0 4 Mar 88 18:51 /dev/d1057all
- X 1,119 brw-r--r-- 1 root 0 30 May 86 19:12 /dev/dh1d
- X.ft R
- X.in -.5i
- X.fi
- X.SH WARNINGS
- XThere may be special device types which \fBle\fR will not handle. In
- Xthis case the device type will be shown as a "?" in the mode.
- X.SH FILES
- X.SH SEE ALSO
- Xls.
- X.SH DIAGNOSTICS
- XVery large directories may produce a diagnostic as internal table
- Xoverflow.
- X.SH LIMITATIONS
- X.SH AUTHOR
- XPeter da Silva (peter@baylor.uucp), changes and man page by Bill
- XDavidsen (davidsen@crdos1.uucp).
- SHAR_EOF
- chmod 0666 le.1 || echo "restore of le.1 fails"
- echo "x - extracting le.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > le.c &&
- X/* LE.C - enhanced version of ls
- X
- X From net.sources 28 Aug 1985, by Peter da Silva (peter@baylor.uucp).
- X
- X Modifications by bill davidsen (davidsen@crdos1.uucp) 3/28/90.
- X*/
- X
- Xstatic char *SCCSid = "@(#)le.c v1.8 - 3/29/90";
- X
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <sys/dir.h>
- X#include <pwd.h>
- X#include <grp.h>
- X#include <time.h>
- X#ifdef M_XENIX
- X#include <sys/sysmacros.h>
- X#endif
- X
- X#define D_DEV 01
- X#define D_INO 02
- X#define D_MODE 04
- X#define D_LINKS 010
- X#define D_UID 020
- X#define D_GID 040
- X#define D_RDEV 0100
- X#define D_SIZE 0200
- X#define D_ATIME 0400
- X#define D_MTIME 01000
- X#define D_CTIME 02000
- X
- X#define D_SMODE 04000
- X#define D_SUID 010000
- X#define D_SGID 020000
- X#define D_KSIZE 040000
- X
- X#define FALSE 0
- X#define TRUE 1
- X
- X#define MAXENTS 512
- X#define MAXID 64
- X
- Xstruct entry {
- X struct direct e_dir;
- X char filler;
- X struct stat e_stat;
- X} entries[MAXENTS];
- Xint nentries;
- X
- Xchar *errname;
- Xextern int errno;
- Xint xerrno;
- Xchar *tab=" ";
- Xlong maxsize;
- Xchar sizstr[2][10] = {"%6lu%s","%6s%s"};
- Xint dohead=0, dodir=1;
- Xint flags = D_MODE|D_LINKS|D_UID|D_SIZE|D_MTIME;
- Xint datefmt = 0;
- X
- Xchar *emesg[3]={
- X "No such error",
- X#define TOO_MANY 1
- X "Too many directory entries",
- X 0
- X};
- X
- Xgetdir(dir)
- Xchar *dir;
- X{
- X int entcmp();
- X char *nameof();
- X FILE *fp;
- X int valid;
- X
- X if(!(fp = fopen(dir, "r"))) {
- X errname=dir;
- X return FALSE;
- X }
- X
- X maxsize=0L;
- X for(nentries=0;
- X nentries<MAXENTS &&
- X fread((char *)&entries[nentries].e_dir,
- X sizeof entries[nentries].e_dir, 1, fp)>0;
- X nentries += valid) {
- X if(valid=entries[nentries].e_dir.d_ino?1:0) {
- X entries[nentries].filler=0;
- X if(stat(nameof(entries[nentries].e_dir.d_name, dir),
- X &entries[nentries].e_stat
- X )==-1
- X ) {
- X fclose(fp);
- X errname=nameof(entries[nentries].e_dir.d_name,
- X dir);
- X return FALSE;
- X }
- X if(entries[nentries].e_stat.st_size>maxsize)
- X maxsize=entries[nentries].e_stat.st_size;
- X }
- X }
- X
- X if(nentries>=MAXENTS) {
- X errno=0;
- X xerrno=TOO_MANY;
- X errname=dir;
- X return FALSE;
- X }
- X
- X fclose(fp);
- X
- X qsort(entries, nentries, sizeof(struct entry), entcmp);
- X
- X setsize(maxsize);
- X
- X return TRUE;
- X}
- X
- Xsetsize(size)
- Xlong size;
- X{
- X char tmp[32];
- X int siz;
- X sprintf(tmp, "%lu", size);
- X siz=strlen(tmp);
- X if(siz<6) siz=6;
- X sprintf(sizstr[0], "%%%dlu%%s", siz);
- X sprintf(sizstr[1], "%%%ds%%s", siz);
- X if(dohead) {
- X header();
- X dohead=0;
- X }
- X}
- X
- Xchar *
- Xnameof(name, dir)
- Xchar *name, *dir;
- X{
- X char nambuf[BUFSIZ];
- X
- X if(!dir[0])
- X return name;
- X if(dir[0]=='.' && !dir[1])
- X return name;
- X else if(dir[0]=='/' && !dir[1]) {
- X sprintf(nambuf, "/%s", name);
- X return nambuf;
- X } else {
- X sprintf(nambuf, "%s/%s", dir, name);
- X return nambuf;
- X }
- X}
- X
- Xpname(name)
- Xchar *name;
- X{
- X int len = 0;
- X
- X for(;*name; name++)
- X if(*name<' ') { printf("^%c", *name+'@'); len+=2; }
- X else if(*name=='\177') { printf("^?"); len+=2; }
- X else if(*name>'\177') { printf("\\%03o", *name); len += 4; }
- X else { putchar(*name); len++; }
- X return len;
- X}
- X
- Xentcmp(e1, e2)
- Xstruct entry *e1, *e2;
- X{
- X return strcmp(e1->e_dir.d_name, e2->e_dir.d_name);
- X}
- X
- Xfdump(dir)
- Xchar *dir;
- X{
- X struct stat sbuf;
- X
- X if(stat(dir, &sbuf)==-1) {
- X errname=dir;
- X return FALSE;
- X } else
- X if(dodir && (sbuf.st_mode&S_IFMT)==S_IFDIR) {
- X if(getdir(dir))
- X return dump(dir);
- X else
- X return FALSE;
- X } else {
- X setsize(sbuf.st_size);
- X statout(dir, &sbuf, ".");
- X return TRUE;
- X }
- X}
- X
- Xdump(dir)
- Xchar *dir;
- X{
- X int i, j;
- X int chars;
- X
- X if(flags==0) {
- X for(i=0; i<=nentries/5; i++) {
- X chars = 0;
- X for(j=0; j<5; j++) {
- X if(i+j*nentries/5<nentries)
- X chars +=
- X pname(entries[i+j*nentries/5].e_dir.d_name);
- X if(chars<8) { putchar('\t'); chars=8; }
- X if(chars<16) { putchar('\t'); chars=16; }
- X else { putchar(' '); chars++; }
- X chars %= 16;
- X }
- X putchar('\n');
- X }
- X }
- X else for(i=0; i<nentries; i++)
- X statout(entries[i].e_dir.d_name,
- X &entries[i].e_stat, dir);
- X return TRUE;
- X}
- X
- Xstatout(name, sbuf, dir)
- Xchar *name;
- Xstruct stat *sbuf;
- Xchar *dir;
- X{
- X char *u_name(), *g_name();
- X
- X if(flags&D_DEV)
- X printf("%3d,%3d%s",
- X major(sbuf->st_dev),
- X minor(sbuf->st_dev),
- X tab);
- X if(flags&D_RDEV)
- X printf("%3d,%3d%s",
- X major(sbuf->st_rdev),
- X minor(sbuf->st_rdev),
- X tab);
- X if(flags&D_INO)
- X printf("%5u%s", sbuf->st_ino, tab);
- X if(flags&D_SMODE)
- X printf("%6o%s", sbuf->st_mode, tab);
- X if(flags&D_MODE) {
- X int mode = sbuf->st_mode;
- X if((mode&S_IFMT)==S_IFCHR) putchar('c');
- X else if((mode&S_IFMT)==S_IFBLK) putchar('b');
- X else if((mode&S_IFMT)==S_IFDIR) putchar('d');
- X else if((mode&S_IFMT)==S_IFREG) putchar('-');
- X else if((mode&S_IFMT)==S_IFIFO) putchar('p');
- X else putchar('?');
- X triad((mode>>6)&7, mode&S_ISUID, 's');
- X triad((mode>>3)&7, mode&S_ISGID, 's');
- X triad(mode&7, mode&S_ISVTX, 't');
- X printf("%s", tab);
- X }
- X if(flags&D_LINKS)
- X printf("%3u%s", sbuf->st_nlink, tab);
- X if(flags&D_SUID)
- X printf("%3d%s", sbuf->st_uid, tab);
- X if(flags&D_UID)
- X printf("%-8s%s", u_name(sbuf->st_uid), tab);
- X if(flags&D_SGID)
- X printf("%3d%s", sbuf->st_gid, tab);
- X if(flags&D_GID)
- X printf("%-8s%s", g_name(sbuf->st_gid), tab);
- X if(flags&D_SIZE)
- X printf(sizstr[0], sbuf->st_size, tab);
- X if(flags&D_KSIZE)
- X printf("%6dk%s", (int)(sbuf->st_size)/1024, tab);
- X if((flags&~(D_ATIME|D_MTIME|D_CTIME)) &&
- X (flags&(D_ATIME|D_MTIME|D_CTIME))) putchar(' ');
- X if(flags&D_ATIME)
- X printime(&sbuf->st_atime);
- X if(flags&D_MTIME)
- X printime(&sbuf->st_mtime);
- X if(flags&D_CTIME)
- X printime(&sbuf->st_ctime);
- X pname(nameof(name, dir));
- X putchar('\n');
- X}
- X
- Xstruct idtab {
- X int id_id;
- X char id_name[10];
- X} u_list[MAXID], g_list[MAXID];
- Xint u_ptr=0, g_ptr=0;
- X
- Xchar *
- Xu_name(uid)
- Xint uid;
- X{
- X int i;
- X struct passwd *pwptr, *getpwuid();
- X
- X for(i=0; i<u_ptr; i++)
- X if(u_list[i].id_id==uid)
- X return u_list[i].id_name;
- X
- X u_list[u_ptr].id_id=uid;
- X
- X if(pwptr=getpwuid(uid)) {
- X for(i=0; pwptr->pw_name[i]>' '; i++)
- X u_list[u_ptr].id_name[i]=pwptr->pw_name[i];
- X u_list[u_ptr].id_name[i]=0;
- X } else
- X sprintf(u_list[u_ptr].id_name, "%d", uid);
- X
- X return u_list[u_ptr++].id_name;
- X}
- X
- Xchar *
- Xg_name(gid)
- Xint gid;
- X{
- X int i;
- X struct group *grptr, *getgrgid();
- X
- X for(i=0; i<g_ptr; i++)
- X if(g_list[i].id_id==gid)
- X return g_list[i].id_name;
- X
- X g_list[g_ptr].id_id=gid;
- X
- X if(grptr=getgrgid(gid)) {
- X for(i=0; grptr->gr_name[i]>' '; i++)
- X g_list[g_ptr].id_name[i]=grptr->gr_name[i];
- X g_list[g_ptr].id_name[i]=0;
- X } else
- X sprintf(g_list[g_ptr].id_name, "%d", gid);
- X
- X return g_list[g_ptr++].id_name;
- X}
- X
- Xprintime(clock)
- Xlong *clock;
- X{
- X struct tm *tmbuf, *localtime();
- X static char *months[12]= {
- X "Jan","Feb","Mar","Apr","May","Jun",
- X "Jul","Aug","Sep","Oct","Nov","Dec"
- X };
- X
- X tmbuf=localtime(clock);
- X if (datefmt) {
- X printf("%4d-%02d-%02d %02d:%02d %s",
- X tmbuf->tm_year+1900,
- X tmbuf->tm_mon+1,
- X tmbuf->tm_mday,
- X tmbuf->tm_hour,
- X tmbuf->tm_min,
- X tab);
- X }
- X else {
- X printf("%2d %3s %02d %2d:%02d %s",
- X tmbuf->tm_mday,
- X months[tmbuf->tm_mon],
- X tmbuf->tm_year,
- X tmbuf->tm_hour,
- X tmbuf->tm_min,
- X tab);
- X }
- X}
- X
- Xheader()
- X{
- X if(flags&D_DEV)
- X printf("%7s%s", "IDev", tab);
- X if(flags&D_RDEV)
- X printf("%7s%s", "Rdev", tab);
- X if(flags&D_INO)
- X printf("%5s%s", "Inode", tab);
- X if(flags&D_SMODE)
- X printf("%6s%s", "Mode", tab);
- X if(flags&D_MODE)
- X printf("%-10s%s", "Long mode", tab);
- X if(flags&D_LINKS)
- X printf("%3s%s", "Lnx", tab);
- X if(flags&D_SUID)
- X printf("%3s%s", "UID", tab);
- X if(flags&D_UID)
- X printf("%-8s%s", "User", tab);
- X if(flags&D_SGID)
- X printf("%3s%s", "GID", tab);
- X if(flags&D_GID)
- X printf("%-8s%s", "Group", tab);
- X if(flags&D_SIZE)
- X printf(sizstr[1], "Size", tab);
- X if(flags&D_KSIZE)
- X printf(" Size %s", tab);
- X if((flags&~(D_ATIME|D_MTIME|D_CTIME)) &&
- X (flags&(D_ATIME|D_MTIME|D_CTIME))) putchar(' ');
- X if(flags&D_ATIME)
- X printf("%-*s%s", datefmt+16, "Access time", tab);
- X if(flags&D_MTIME)
- X printf("%-*s%s", datefmt+16, "Modify time", tab);
- X if(flags&D_CTIME)
- X printf("%-*s%s", datefmt+16, "Inode time", tab);
- X if(flags)
- X printf("%s\n", "File name");
- X}
- X
- Xtriad(bits, special, code)
- Xint bits, special;
- Xchar code;
- X{
- X if(bits&4) putchar('r');
- X else putchar('-');
- X
- X if(bits&2) putchar('w');
- X else putchar('-');
- X
- X if(special) putchar(code);
- X else if(bits&1) putchar('x');
- X else putchar('-');
- X}
- X
- Xmain(ac, av)
- Xint ac;
- Xchar **av;
- X{
- X int i, j;
- X int exit_status = 0;
- X int filed=0;
- X
- X for(i=1; i<ac; i++) {
- X if(av[i][0]=='-')
- X for(j=1; av[i][j]; j++)
- X switch(av[i][j]) {
- X case 'T':
- X if(av[i][j+1])
- X tab = &av[i][++j];
- X else
- X tab = &av[++i][j=0];
- X while(av[i][j]) j++;
- X j--;
- X break;
- X case 'N': flags = 0; break;
- X case 'A': flags = -1; break;
- X case 'D': dodir=!dodir; break;
- X case 'd': flags ^= D_DEV; break;
- X case 'i': flags ^= D_INO; break;
- X case 'm': flags ^= D_MODE; break;
- X case 'M': flags ^= D_SMODE; break;
- X case 'l': flags ^= D_LINKS; break;
- X case 'u': flags ^= D_UID; break;
- X case 'U': flags ^= D_SUID; break;
- X case 'g': flags ^= D_GID; break;
- X case 'G': flags ^= D_SGID; break;
- X case 'r': flags ^= D_RDEV; break;
- X case 's': flags ^= D_SIZE; break;
- X case 'k': flags ^= D_KSIZE; break;
- X case 'a': flags ^= D_ATIME; break;
- X case 't': flags ^= D_MTIME; break;
- X case 'c': flags ^= D_CTIME; break;
- X case 'f': datefmt = 1; break;
- X case 'H': dohead = 1; break;
- X default: printf("unknown option %c\n", av[i][j]);
- X case 'h': helpuser(); exit(0);
- X }
- X else {
- X filed=1;
- X if(!fdump(av[i])) {
- X fperror(av[0], errname);
- X exit_status=errno?errno:(-xerrno);
- X }
- X }
- X }
- X if(!filed)
- X if(!fdump(".")) {
- X fperror(av[0], errname);
- X exit_status=errno;
- X }
- X
- X if(dohead) header();
- X exit(exit_status);
- X}
- X
- Xfperror(prog, file)
- Xchar *prog, *file;
- X{
- X fprintf(stderr, "%s -- ", prog);
- X if(errno)
- X perror(file);
- X else
- X fprintf(stderr, "%s: %s\n", file, emesg[xerrno]);
- X}
- X
- Xhelpuser() {
- X int n;
- X
- X static char *helpit[] = {
- X "",
- X "Usage: le [-A|-N] [-diMmlUuGgrsatc] [-Ttab] [-Hh] [-D] [file]...",
- X "",
- X "-d Toggle 'dev' flag. -r Toggle 'rdev' flag.",
- X "-i Toggle 'inode' flag. -s Toggle 'size' flag.",
- X "-m Toggle 'mode' flag. -k Toggle 'ksize' flag.",
- X "-M Toggle 'short mode' flag. -a Toggle 'atime' flag.",
- X "-l Toggle 'links' flag. -t Toggle 'mtime' flag.",
- X "-u Toggle 'user' flag. -c Toggle 'ctime' flag.",
- X "-U Toggle 'short user' flag. -f format dates yyyy-mm-dd",
- X "-g Toggle 'group' flag. to facilitate sorting",
- X "-G Toggle 'short group' flag.",
- X "",
- X "-H Force output of the header.",
- X "-N (None) Clear all flags.",
- X "-A (All) Set all flags.",
- X "-D Dont list directories (like ls -d).",
- X "-Ttab Use the string 'tab' to seperate fields instead of space.",
- X "",
- X "Options are evaluated *left to right!*",
- X NULL
- X };
- X
- X for (n=0; helpit[n] != NULL; n++)
- X printf("\t%s\n", helpit[n]);
- X}
- SHAR_EOF
- chmod 0444 le.c || echo "restore of le.c fails"
- exit 0
- --
- bill davidsen (davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
- "Stupidity, like virtue, is its own reward" -me
-