1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1989-2010 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A***********************************************************************/ 1N/A * ls -- list file status 1N/A"[-?\n@(#)$Id: ls (AT&T Research) 2010-05-25 $\n]" 1N/A"[+NAME?ls - list files and/or directories]" 1N/A"[+DESCRIPTION?For each directory argument \bls\b lists the contents; for each" 1N/A" file argument the name and requested information are listed." 1N/A" The directory \b.\b is assumed if no file arguments appear." 1N/A" The listing is sorted by file name by default, except that file" 1N/A" arguments are listed before directories.]" 1N/A"[+?Multi-column terminal output display width is determined by \bioctl\b(2)" 1N/A" and/or the \bCOLUMNS\b environment variable.]" 1N/A"[+?\bgetconf PATH_RESOLVE\b determines how symbolic links are handled. This" 1N/A" can be explicitly overridden by the \b--logical\b, \b--metaphysical\b," 1N/A" and \b--physical\b options below. \bPATH_RESOLVE\b can be one of:]{" 1N/A" [+logical?Follow all symbolic links.]" 1N/A" [+metaphysical?Follow command argument symbolic links," 1N/A" otherwise don't follow.]" 1N/A" [+physical?Don't follow symbolic links.]" 1N/A"[a:all?List entries starting with \b.\b; turns off \b--almost-all\b.]" 1N/A"[A:almost-all?List all entries but \b.\b and \b..\b; turns off \b--all\b.]" 1N/A"[b:escape?Print escapes for nongraphic characters.]" 1N/A"[B:ignore-backups?Do not list entries ending with ~.]" 1N/A"[c:ctime?Sort by change time; list ctime with \b--long\b.]" 1N/A"[C:multi-column?List entries by columns.]" 1N/A"[d:directory?List directory entries instead of contents.]" 1N/A"[D:define?Define \akey\a with optional \avalue\a. \avalue\a will be expanded" 1N/A" when \b%(\b\akey\a\b)\b is specified in \b--format\b. \akey\a may" 1N/A" override internal \b--format\b identifiers.]:[key[=value]]]" 1N/A"[e:long-iso|long-time?Equivalent to \b--long --time-style=long-iso\b.]" 1N/A"[E:full-iso|full-time?Equivalent to \b--long --time-style=full-iso\b.]" 1N/A"[f:force?Force each argument to be interpreted as a directory and list" 1N/A" the name found in each slot in the physical directory order. Turns" 1N/A" on \b-aU\b and turns off \b-lrst\b. The results are undefined for" 1N/A" non-directory arguments.]" 1N/A"[Z:format?Append to the listing format string. \aformat\a follows" 1N/A" \bprintf\b(3) conventions, except that \bsfio\b(3) inline ids" 1N/A" are used instead of arguments:" 1N/A" %[-+]][\awidth\a[.\aprecis\a[.\abase\a]]]]]](\aid\a[:\asubformat\a]])\achar\a." 1N/A" If \achar\a is \bs\b then the string form of the item is listed," 1N/A" otherwise the corresponding numeric form is listed. \asubformat\a" 1N/A" overrides the default formatting for \aid\a. Supported \aid\as" 1N/A" and \asubformat\as are:]:[format]{" 1N/A" [+atime?access time]" 1N/A" [+blocks?size in blocks]" 1N/A" [+ctime?change time]" 1N/A" [+device?device number]" 1N/A" [+devmajor?major device number]" 1N/A" [+devminor?minor device number]" 1N/A" [+dir.blocks?directory blocks]" 1N/A" [+dir.bytes?directory size in bytes]" 1N/A" [+dir.files?directory file count]" 1N/A" [+flags?command line flags in effect]" 1N/A" [+header?listing header]" 1N/A" [+ino?serial number]" 1N/A" [+linkop?link operation: => for symbolic, == for hard]" 1N/A" [+linkname?symbolic link text]" 1N/A" [+linkpath?symbolic link text]" 1N/A" [+mark?file or directory mark character]" 1N/A" [+markdir?directory mark character]" 1N/A" [+mode?access mode]" 1N/A" [+mtime?modification time]" 1N/A" [+name?entry name]" 1N/A" [+nlink?hard link count]" 1N/A" [+path?file path from original root dir]" 1N/A" [+perm?access permissions]" 1N/A" [+size?file size in bytes]" 1N/A" [+summary?listing summary info]" 1N/A" [+total.blocks?running total block count]" 1N/A" [+total.bytes?running total size in bytes]" 1N/A" [+total.files?running total file count]" 1N/A" [+trailer?listing trailer]" 1N/A" [+----?subformats ----]" 1N/A" [+case\b::\bp\b\a1\a::\bs\b\a1\a::...::\bp\b\an\a::\bs\b\an\a?Expands" 1N/A" to \bs\b\ai\a if the value of \aid\a matches the shell" 1N/A" pattern \bp\b\ai\a, or the empty string if there is no" 1N/A" [+mode?The integral value as a \bfmtmode\b(3) string.]" 1N/A" [+perm?The integral value as a \bfmtperm\b(3) string.]" 1N/A" [+time[=\aformat\a]]?The integral value as a \bstrftime\b(3)" 1N/A" string. For example," 1N/A" \b--format=\"%8(mtime)u %(ctime:time=%H:%M:%S)s\"\b" 1N/A" lists the mtime in seconds since the epoch and the" 1N/A" ctime as hours:minutes:seconds.]" 1N/A"[F:classify?Append a character for typing each entry. Turns on \b--physical\b.]" 1N/A"[g:group?\b--long\b with no owner info.]" 1N/A"[G?\b--long\b with no group info.]" 1N/A"[h:scale|binary-scale|human-readable?Scale sizes to powers of 1024 { Ki Mi Gi Ti Pi Xi }.]" 1N/A"[i:inode?List the file serial number.]" 1N/A"[I:ignore?Do not list implied entries matching shell \apattern\a.]:[pattern]" 1N/A"[k:kilobytes?Use 1024 blocks instead of 512.]" 1N/A"[K:shell-quote?Enclose entry names in shell $'...' if necessary.]" 1N/A"[l:long|verbose?Use a long listing format.]" 1N/A"[m:commas|comma-list?List names as comma separated list.]" 1N/A"[n:numeric-uid-gid?List numeric user and group ids instead of names.]" 1N/A"[N:literal|show-controls-chars?Print raw entry names (don't treat e.g. control characters specially).]" 1N/A"[o:owner?\b--long\b with no group info.]" 1N/A"[O?\b--long\b with no owner info.]" 1N/A"[p:markdir?Append / to each directory name.]" 1N/A"[q:hide-control-chars?Print ? instead of non graphic characters.]" 1N/A"[Q:quote-name?Enclose all entry names in \"...\".]" 1N/A"[J:quote-style|quoting-style?Quote entry names according to \astyle\a:]:[style:=question]{" 1N/A" [c:C?C \"...\" quote.]" 1N/A" [e:escape?\b\\\b escape if necessary.]" 1N/A" [l:literal?No quoting.]" 1N/A" [q:question?Replace unprintable characters with \b?\b.]" 1N/A" [s:shell?Shell $'...' quote if necessary.]" 1N/A" [S:shell-always?Shell $'...' every name.]" 1N/A"[r:reverse?Reverse order while sorting.]" 1N/A"[R:recursive?List subdirectories recursively.]" 1N/A"[s:size?Print size of each file, in blocks.]" 1N/A"[S:bysize?Sort by file size.]" 1N/A"[t:?Sort by modification time; list mtime with \b--long\b.]" 1N/A"[T:tabsize?Ignored by this implementation.]#[columns]" 1N/A"[u:access?Sort by last access time; list atime with \b--long\b.]" 1N/A"[U?Equivalent to \b--sort=none\b.]" 1N/A"[V:colors|colours?\akey\a determines when color is used to distinguish" 1N/A" types:]:?[key:=never]{" 1N/A" [n:never?Never use color.]" 1N/A" [a:always?Always use color.]" 1N/A" [t:tty|auto?Use color when output is a tty.]" 1N/A"[w:width?Set the screen width to \ascreen-width\a and the screen height" 1N/A" to \ascreen-height\a if specified.]:[[screen-heightX]]screen-width]" 1N/A"[W:time?Display \akey\a time instead of the modification time:]:[key]{" 1N/A" [a:atime|access|use?access time]" 1N/A" [c:ctime|status?status change time]" 1N/A" [m:mtime|time?modify time]" 1N/A"[x:across?List entries by lines instead of by columns.]" 1N/A"[X:extension?Sort alphabetically by entry extension.]" 1N/A"[y:sort?Sort by \akey\a:]:?[key]{" 1N/A" [a:atime|access|use?Access time.]" 1N/A" [c:ctime|status?Status change time.]" 1N/A" [x:extension?File name extension.]" 1N/A" [m:mtime|time?Modify time.]" 1N/A" [f:name?File name.]" 1N/A" [n:none?Don't sort.]" 1N/A" [s:size|blocks?File size.]" 1N/A" [v:version?File name version.]" 1N/A"[Y:layout?Listing layout \akey\a:]:[key]{" 1N/A" [a:across|horizontal?Multi-column across the page.]" 1N/A" [c:comma?Comma separated names across the page.]" 1N/A" [l:long|verbose?Long listing.]" 1N/A" [v:multi-column|vertical?Multi-column by column.]" 1N/A" [1:single-column?One column down the page.]" 1N/A"[z:time-style?List the time according to \astyle\a:]:[style]{" 1N/A" [10:posix-iso?No change for the C or posix locales, \biso\b otherwise.]" 1N/A" [11:posix-full-iso?No change for the C or posix locales, \bfull-iso\b" 1N/A" [12:+\aformat\a?A \bdate\b(1) +\aformat\a.]" 1N/A"[1:one-column?List one file per line.]" 1N/A"[L:logical|follow?Follow symbolic links. The default is determined by" 1N/A" \bgetconf PATH_RESOLVE\b.]" 1N/A"[H:metaphysical?Follow command argument symbolic links, otherwise don't" 1N/A" follow. The default is determined by \bgetconf PATH_RESOLVE\b.]" 1N/A"[P:physical?Don't follow symbolic links. The default is determined by" 1N/A" \bgetconf PATH_RESOLVE\b.]" 1N/A"[101:block-size?Use \ablocksize\a blocks.]#[blocksize]" 1N/A"[102:decimal-scale|thousands?Scale sizes to powers of 1000 { K M G T P X }.]" 1N/A"[103:dump?Print the generated \b--format\b string on the standard output" 1N/A"[104:testdate?\b--format\b time values newer than \adate\a will be printed" 1N/A" as \adate\a. Used for regression testing.]:[date]" 1N/A"[105:testsize?Shift file sizes left \ashift\a bits and set file block counts" 1N/A" to the file size divided by 512. Used for regression testing.]#[shift]" 1N/A"[+SEE ALSO?\bchmod\b(1), \bfind\b(1), \bgetconf\b(1), \btw\b(1)]" 1N/A"[+BUGS?Can we add options to something else now?]" 1N/A#
define AFTER 1 /* space after last column */ 1N/Atypedef struct /* sfkeyprintf() keys */ 1N/Atypedef struct /* list state */ 1N/Atypedef struct /* program state */ 1N/A char flags[
64];
/* command line option flags */ 1N/A int adjust;
/* key() print with adjustment */ 1N/A int comma;
/* LS_COMMAS ftw.level crossing */ 1N/A char*
ignore;
/* ignore files matching this */ 1N/A"%(dir.count:case;0;;1;%(path)s:\n;*;\n%(path)s:\n)s" 1N/A"%(flags:case;*d*;;*[ls]*;total %(dir.blocks)u\n)s" 1N/A * return a copy of s with unprintable chars replaced by ? 1N/A * sfkeyprintf() lookup 1N/A register char* s = 0;
1N/A * print info on a single file 1N/A * parent directory name is dirnam of dirlen chars 1N/A * -H == --hairbrained 1N/A * no way around it - this is bud tugley 1N/A * symlinks should be no more visible than mount points 1N/A * but I wear my user hat more than my administrator hat 1N/A * pr() ftw directory child list in column order 1N/A * directory name is dirnam of dirlen chars 1N/A * count is the number of VISIBLE children 1N/A * length is the length of the longest VISIBLE child 1N/A c = (i -
1) / n +
1;
1N/A for (j = 0; j < c; j++)
1N/A for (l = 0, r = j; l < n && r < i; r += c, l++)
1N/A c = (i -
1) / n +
1;
1N/A for (j = 0; j < c; j++)
1N/A for (l = 0, r = j; l < n && r < i; r += c, l++)
1N/A for (j = 0; j <= i; j += c)
1N/A for (l = 0, w = j; l < k && w < i; l++, w++)
1N/A pr(
lp, x[w], l < (k -
1) && w < (i -
1) ?
siz[l] : 0);
1N/A n = m = (i + c -
1) / c;
1N/A n -= (r + c -
1) / c;
1N/A for (l = 0; l < n && j < i; j++, l++)
1N/A for (l = 0; l < n && j < i; j++, l++)
1N/A for (j = 0; j < n; j++)
1N/A for (l = 0, w = j; l < k && w < i; l++, w += n)
1N/A pr(
lp, x[w], l < (k -
1) && w < (i - n) ?
siz[l] : 0);
1N/A * order child entries 1N/A * list a directory and its children 1N/A * list info on a single file 1N/A static char fmt_color[] =
"%(mode:case:d*:\\E[01;34m%(name)s\\E[0m:l*:\\E[01;36m%(name)s\\E[0m:*x*:\\E[01;32m%(name)s\\E[0m:*:%(name)s)s";
1N/A if (*e ==
'x' || *e ==
'X' || *e ==
'.' || *e ==
'+')
1N/A sfputr(
fmt,
" %8(device:case::%(size)u:*:%(device)s)s", -
1);
1N/A sfputr(
fmt,
"%(linkop:case:?*: %(linkop)s %(linkpath)s)s", -
1);