ls.c File Reference

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <time.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <termios.h>
#include <sys/ioctl.h>

Include dependency graph for ls.c:

Go to the source code of this file.

Data Structures

struct  idname
struct  file

Defines

#define ifmt(mode)   l_ifmt[((mode) >> 12) & 0xF]
#define nil   0
#define major(dev)   ((int) (((dev) >> 8) & 0xFF))
#define minor(dev)   ((int) (((dev) >> 0) & 0xFF))
#define SUPER_ID   uid
#define status   stat
#define BLOCK   512
#define ST_BLOCKS   1
#define NSEP   3
#define MAXCOLS   128
#define NNAMES   (1 << (sizeof(int) + sizeof(char *)))
#define uidname(uid)   idname((uid), PASSWD)
#define gidname(gid)   idname((gid), GROUP)
#define delpath(didx)   (path[pidx= didx]= 0)
#define L_INODE   0x0001
#define L_BLOCKS   0x0002
#define L_EXTRA   0x0004
#define L_MODE   0x0008
#define L_LONG   0x0010
#define L_GROUP   0x0020
#define L_BYTIME   0x0040
#define L_ATIME   0x0080
#define L_CTIME   0x0100
#define L_MARK   0x0200
#define L_MARKDIR   0x0400
#define L_TYPE   0x0800
#define L_LONGTIME   0x1000
#define L_DIR   0x2000
#define L_KMG   0x4000
#define PAST   (26*7*24*3600L)
#define FUTURE   ( 1*7*24*3600L)
#define K   1024L
#define T   1000L
#define nblocks(f)   ((f)->blocks)
#define nblk2k(nb)   (((nb) + (1024 / BLOCK - 1)) / (1024 / BLOCK))
#define spaces(n)   (nsp= (n))
#define terpri()   (nsp= 0, putchar('\n'))

Enumerations

enum  whatmap { PASSWD, GROUP }
enum  {
  W_COL, W_INO, W_BLK, W_NLINK,
  W_UID, W_GID, W_SIZE, W_NAME,
  MAXFLDS
}
enum  depth { SURFACE, SURFACE1, SUBMERGED }
enum  state { BOTTOM, SINKING, FLOATING }

Functions

void heaperr (void)
void * allocate (size_t n)
void * reallocate (void *a, size_t n)
void setflags (char *flgs)
int present (int f)
void report (char *f)
char * idname (unsigned id, enum whatmap map)
void addpath (int *didx, char *name)
void setstat (struct file *f, struct stat *stp)
static char * timestamp (struct file *f)
char * permissions (struct file *f)
void numeral (int i, char **pp)
char * cxsize (struct file *f)
static void mergesort (struct file **al)
int namecmp (struct file *f1, struct file *f2)
int mtimecmp (struct file *f1, struct file *f2)
int atimecmp (struct file *f1, struct file *f2)
int ctimecmp (struct file *f1, struct file *f2)
int typecmp (struct file *f1, struct file *f2)
int revcmp (struct file *f1, struct file *f2)
static void sort (struct file **al)
filenewfile (char *name)
void pushfile (struct file **flist, struct file *new)
void delfile (struct file *old)
filepopfile (struct file **flist)
int dotflag (char *name)
int adddir (struct file **aflist, char *name)
off_t countblocks (struct file *flist)
void printname (char *name)
int mark (struct file *f, int doit)
void maxise (unsigned char *aw, int w)
int numwidth (unsigned long n)
int numxwidth (unsigned long n)
void print1 (struct file *f, int col, int doit)
int countfiles (struct file *flist)
void columnise (struct file *flist, int nplin)
int print (struct file *flist, int nplin, int doit)
void listfiles (struct file *flist, enum depth depth, enum state state)
int main (int argc, char **argv)

Variables

char l_ifmt [] = "0pcCd?bB-?l?s???"
int ncols = 79
char * arg0
int uid
int gid
int ex = 0
int istty
char allowed [] = "acdfghilnpqrstu1ACDFLMRTX"
char flags [sizeof(allowed)]
char arg0flag [] = "cdfmrtx"
idnameuids [NNAMES]
idnamegids [NNAMES]
char * path
int plen = 0
int pidx = 0
int field = 0
static int(* CMP )(struct file *f1, struct file *f2)
static int(* rCMP )(struct file *f1, struct file *f2)
unsigned char fieldwidth [MAXCOLS][MAXFLDS]
static int nsp = 0
filefilecol [MAXCOLS]
int nfiles
int nlines


Define Documentation

#define BLOCK   512
 

Definition at line 58 of file ls.c.

#define delpath didx   )     (path[pidx= didx]= 0)
 

Definition at line 228 of file ls.c.

Referenced by cleandir(), listfiles(), main(), and print1().

#define FUTURE   ( 1*7*24*3600L)
 

Definition at line 286 of file ls.c.

Referenced by timestamp().

#define gidname gid   )     idname((gid), GROUP)
 

Definition at line 191 of file ls.c.

Referenced by print1().

#define ifmt mode   )     l_ifmt[((mode) >> 12) & 0xF]
 

Definition at line 17 of file ls.c.

Referenced by permissions(), and typecmp().

#define K   1024L
 

Definition at line 389 of file ls.c.

#define L_ATIME   0x0080
 

Definition at line 240 of file ls.c.

Referenced by main(), sort(), and timestamp().

#define L_BLOCKS   0x0002
 

Definition at line 234 of file ls.c.

Referenced by listfiles(), main(), and print1().

#define L_BYTIME   0x0040
 

Definition at line 239 of file ls.c.

Referenced by main(), and sort().

#define L_CTIME   0x0100
 

Definition at line 241 of file ls.c.

Referenced by main(), sort(), and timestamp().

#define L_DIR   0x2000
 

Definition at line 246 of file ls.c.

Referenced by main().

#define L_EXTRA   0x0004
 

Definition at line 235 of file ls.c.

Referenced by main(), permissions(), and print1().

#define L_GROUP   0x0020
 

Definition at line 238 of file ls.c.

Referenced by main(), and print1().

#define L_INODE   0x0001
 

Definition at line 233 of file ls.c.

Referenced by main(), and print1().

#define L_KMG   0x4000
 

Definition at line 247 of file ls.c.

Referenced by main(), and print1().

#define L_LONG   0x0010
 

Definition at line 237 of file ls.c.

Referenced by listfiles(), main(), and print1().

#define L_LONGTIME   0x1000
 

Definition at line 245 of file ls.c.

Referenced by main(), print1(), and timestamp().

#define L_MARK   0x0200
 

Definition at line 242 of file ls.c.

Referenced by main(), and mark().

#define L_MARKDIR   0x0400
 

Definition at line 243 of file ls.c.

Referenced by main(), and mark().

#define L_MODE   0x0008
 

Definition at line 236 of file ls.c.

Referenced by main(), and print1().

#define L_TYPE   0x0800
 

Definition at line 244 of file ls.c.

Referenced by main(), and sort().

#define major dev   )     ((int) (((dev) >> 8) & 0xFF))
 

Definition at line 38 of file ls.c.

#define MAXCOLS   128
 

Definition at line 74 of file ls.c.

Referenced by listfiles().

#define minor dev   )     ((int) (((dev) >> 0) & 0xFF))
 

Definition at line 39 of file ls.c.

#define nblk2k nb   )     (((nb) + (1024 / BLOCK - 1)) / (1024 / BLOCK))
 

Definition at line 442 of file ls.c.

Referenced by listfiles(), and print1().

#define nblocks f   )     ((f)->blocks)
 

Definition at line 435 of file ls.c.

Referenced by alloc(), atapi_transfer(), countblocks(), main(), and print1().

#define nil   0
 

Definition at line 19 of file ls.c.

#define NNAMES   (1 << (sizeof(int) + sizeof(char *)))
 

Definition at line 140 of file ls.c.

Referenced by idname().

#define NSEP   3
 

Definition at line 72 of file ls.c.

Referenced by print1().

#define PAST   (26*7*24*3600L)
 

Definition at line 284 of file ls.c.

#define spaces n   )     (nsp= (n))
 

Definition at line 718 of file ls.c.

Referenced by print1(), and Unexpand().

#define ST_BLOCKS   1
 

Definition at line 63 of file ls.c.

#define status   stat
 

Definition at line 51 of file ls.c.

Referenced by _syscall(), _taskcall(), add(), ar_close(), catch_child(), cdiff(), cgiexec(), chk_table(), compretval(), copydir(), copylink(), crypt(), deflateEnd(), do_backward(), do_comm(), do_forward(), do_printer_output(), do_read(), do_status(), do_write(), dosh(), dsp_command(), dsp_ioctl(), ec_check_ints(), ec_recv(), evalloop(), evaltree(), Exec_Shell(), execute(), exitshell(), f_pshinf(), fdc_out(), fdc_results(), get_work(), getpwd(), give_prompt(), handle_events(), kb_wait(), listfiles(), locked(), lp(), m_shell(), main(), make_dir(), match(), mixer_ioctl(), Mkdir(), newdisk(), nr_Uf(), output_done(), pclose(), precmd(), print_capabilities(), readcmd(), reply(), rpclose(), run(), rundiff(), runvec(), safePopenOut(), scrollb(), scrollf(), SH(), sigchar(), startup(), susystem(), System(), system(), test7b(), unix_exec(), wait_for(), and zcopy().

#define SUPER_ID   uid
 

Definition at line 43 of file ls.c.

Referenced by main().

#define T   1000L
 

Definition at line 390 of file ls.c.

Referenced by adjust(), alloc_segments(), command(), cxsize(), display(), do_exec(), do_fork(), do_trace(), dump_stack(), fill(), lookup(), map_addr(), memmap_dmp(), new_mem(), operator<(), operator>(), patch_mem_chunks(), pm_exit(), proctab_dmp(), pstat(), read(), read_core(), read_info(), read_segmap(), setmap(), umap_local(), update(), and write().

 
#define terpri  )     (nsp= 0, putchar('\n'))
 

Definition at line 719 of file ls.c.

#define uidname uid   )     idname((uid), PASSWD)
 

Definition at line 190 of file ls.c.

Referenced by print1().


Enumeration Type Documentation

anonymous enum
 

Enumerator:
W_COL 
W_INO 
W_BLK 
W_NLINK 
W_UID 
W_GID 
W_SIZE 
W_NAME 
MAXFLDS 

Definition at line 684 of file ls.c.

enum depth
 

Enumerator:
SURFACE 
SURFACE1 
SUBMERGED 

Definition at line 958 of file ls.c.

enum state
 

Enumerator:
BOTTOM 
SINKING 
FLOATING 

Definition at line 959 of file ls.c.

enum whatmap
 

Enumerator:
PASSWD 
GROUP 

Definition at line 141 of file ls.c.


Function Documentation

int adddir struct file **  aflist,
char *  name
 

Definition at line 595 of file ls.c.

References access, closedir, d, dotflag(), e, newfile, file::next, nil, opendir, present, pushfile(), readdir, and report().

Referenced by listfiles().

void addpath int *  didx,
char *  name
 

Definition at line 200 of file ls.c.

References allocate(), path, pidx, plen, and reallocate().

void* allocate size_t  n  ) 
 

Definition at line 89 of file ls.c.

References a, heaperr(), malloc(), and nil.

int atimecmp struct file f1,
struct file f2
 

Definition at line 496 of file ls.c.

References f1, and f2.

Referenced by sort().

void columnise struct file flist,
int  nplin
 

Definition at line 900 of file ls.c.

References filecol, i, j, file::next, nfiles, nil, and nlines.

Referenced by print().

off_t countblocks struct file flist  ) 
 

Definition at line 620 of file ls.c.

References file::mode, nblocks, file::next, nil, S_IFDIR, S_IFLNK, S_IFMT, and S_IFREG.

Referenced by listfiles().

int countfiles struct file flist  ) 
 

Definition at line 887 of file ls.c.

References n, file::next, and nil.

Referenced by listfiles().

int ctimecmp struct file f1,
struct file f2
 

Definition at line 501 of file ls.c.

References f1, and f2.

Referenced by sort().

char* cxsize struct file f  ) 
 

Definition at line 392 of file ls.c.

References f, K, numeral(), p, T, and z.

Referenced by print1().

void delfile struct file old  ) 
 

Definition at line 566 of file ls.c.

References free, and file::name.

Referenced by listfiles().

int dotflag char *  name  ) 
 

Definition at line 583 of file ls.c.

Referenced by adddir(), and listfiles().

void heaperr void   ) 
 

Definition at line 83 of file ls.c.

References arg0, exit(), fprintf(), and stderr.

Referenced by allocate(), and reallocate().

char* idname unsigned  id,
enum whatmap  map
 

Definition at line 149 of file ls.c.

References allocate(), getgrgid(), getpwuid(), gids, group::gr_name, i, nil, NNAMES, PASSWD, present, passwd::pw_name, sprintf(), strcpy(), strlen(), and uids.

void listfiles struct file flist,
enum depth  depth,
enum state  state
 

Definition at line 961 of file ls.c.

References adddir(), addpath(), BOTTOM, countblocks(), countfiles(), delfile(), delpath, dotflag(), ENOENT, errno, fflush(), L_BLOCKS, L_LONG, lstat, MAXCOLS, file::mode, file::name, nblk2k, nfiles, nil, path, popfile(), present, print, printf, pushfile(), putchar, r, report(), S_IFDIR, S_IFLNK, S_IFMT, setstat(), SINKING, sort(), st, status, stdout, SURFACE1, and white().

Referenced by main().

int main int  argc,
char **  argv
 

Definition at line 1059 of file ls.c.

References arg0, arg0flag, BOTTOM, close, ex, getegid, getenv(), geteuid, gid, ioctl, isatty, istty, L_ATIME, L_BLOCKS, L_BYTIME, L_CTIME, L_DIR, L_EXTRA, L_GROUP, L_INODE, L_KMG, L_LONG, L_LONGTIME, L_MARK, L_MARKDIR, L_MODE, L_TYPE, listfiles(), lstat, ncols, newfile, nil, O_WRONLY, open, p, present, pushfile(), setflags(), SINKING, status, strchr, strcmp, strrchr(), SUPER_ID, SURFACE, SURFACE1, t, TIOCGWINSZ, uid, and winsize::ws_col.

int mark struct file f,
int  doit
 

Definition at line 652 of file ls.c.

References c, f, L_MARK, L_MARKDIR, putchar, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_ISDIR, S_IXGRP, S_IXOTH, and S_IXUSR.

void maxise unsigned char *  aw,
int  w
 

Definition at line 688 of file ls.c.

References UCHAR_MAX.

Referenced by print1().

static void mergesort struct file **  al  )  [static]
 

Definition at line 450 of file ls.c.

References CMP, file::next, and nil.

Referenced by sort().

int mtimecmp struct file f1,
struct file f2
 

Definition at line 491 of file ls.c.

References f1, and f2.

Referenced by sort().

int namecmp struct file f1,
struct file f2
 

Definition at line 486 of file ls.c.

References f1, f2, and strcmp.

struct file* newfile char *  name  ) 
 

Definition at line 549 of file ls.c.

References allocate(), strcpy(), and strlen().

void numeral int  i,
char **  pp
 

Definition at line 380 of file ls.c.

References a, int(), and itoa().

Referenced by cxsize().

int numwidth unsigned long  n  ) 
 

Definition at line 697 of file ls.c.

References width.

Referenced by print1().

int numxwidth unsigned long  n  ) 
 

Definition at line 707 of file ls.c.

References width.

char* permissions struct file f  ) 
 

Definition at line 326 of file ls.c.

References f, gid, ifmt, L_EXTRA, p, rwx(), S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWUSR, S_IXUSR, and uid.

Referenced by print1().

struct file* popfile struct file **  flist  ) 
 

Definition at line 573 of file ls.c.

References f.

int present int  f  ) 
 

Definition at line 125 of file ls.c.

References flags, nil, and strchr.

int print struct file flist,
int  nplin,
int  doit
 

Definition at line 918 of file ls.c.

References col(), columnise(), fieldwidth, fld, and MAXFLDS.

void print1 struct file f,
int  col,
int  doit
 

Definition at line 721 of file ls.c.

References addpath(), allocate(), cxsize(), delpath, f, fieldwidth, free, gidname, int(), L_BLOCKS, L_EXTRA, L_GROUP, L_INODE, L_KMG, L_LONG, L_LONGTIME, L_MODE, major, mark, MAXFLDS, maxise(), minor, n, nblk2k, nblocks, NSEP, nsp, numwidth(), p, path, permissions(), printf, printname(), putchar, r, readlink, S_IFBLK, S_IFCHR, S_IFLNK, S_IFMT, spaces, strcpy(), strlen(), timestamp(), uidname, W_BLK, W_COL, W_GID, W_INO, W_NAME, W_NLINK, W_SIZE, W_UID, and width.

void printname char *  name  ) 
 

Definition at line 639 of file ls.c.

References c, present, and putchar.

void pushfile struct file **  flist,
struct file new
 

Definition at line 559 of file ls.c.

void* reallocate void *  a,
size_t  n
 

Definition at line 98 of file ls.c.

References heaperr(), nil, and realloc().

Referenced by addpath().

void report char *  f  ) 
 

Definition at line 130 of file ls.c.

References arg0, errno, ex, fprintf(), stderr, and strerror().

int revcmp struct file f1,
struct file f2
 

Definition at line 511 of file ls.c.

References f1, f2, and rCMP.

Referenced by sort().

void setflags char *  flgs  ) 
 

Definition at line 109 of file ls.c.

References allowed, arg0, c, exit(), flags, fprintf(), nil, stderr, strchr, and strlen().

Referenced by main().

void setstat struct file f,
struct stat stp
 

Definition at line 267 of file ls.c.

References f, stat::st_atime, stat::st_ctime, stat::st_gid, stat::st_ino, stat::st_mode, stat::st_mtime, stat::st_nlink, stat::st_rdev, stat::st_size, and stat::st_uid.

Referenced by getstat(), listfiles(), and setmodes().

static void sort struct file **  al  )  [static]
 

Definition at line 513 of file ls.c.

References atimecmp(), CMP, ctimecmp(), L_ATIME, L_BYTIME, L_CTIME, L_TYPE, mergesort(), mtimecmp(), namecmp, nil, present, rCMP, revcmp(), and typecmp().

static char* timestamp struct file f  )  [static]
 

Definition at line 288 of file ls.c.

References date(), f, FUTURE, L_ATIME, L_CTIME, L_LONGTIME, localtime(), month, now, sprintf(), t, time, time_t, tm::tm_hour, tm::tm_mday, tm::tm_min, tm::tm_mon, tm::tm_sec, and tm::tm_year.

Referenced by do_chown(), logmsg(), and print1().

int typecmp struct file f1,
struct file f2
 

Definition at line 506 of file ls.c.

References f1, f2, and ifmt.

Referenced by sort().


Variable Documentation

char allowed[] = "acdfghilnpqrstu1ACDFLMRTX"
 

Definition at line 104 of file ls.c.

Referenced by do_exec(), and setflags().

char* arg0
 

Definition at line 76 of file ls.c.

char arg0flag[] = "cdfmrtx"
 

Definition at line 107 of file ls.c.

Referenced by main().

int(* CMP)(struct file *f1, struct file *f2) [static]
 

Definition at line 447 of file ls.c.

int ex = 0
 

Definition at line 78 of file ls.c.

Referenced by because(), delete(), doexec(), main(), master(), mediator(), perr(), read_map(), report(), scribble_region(), slave(), startprocess(), test5a(), test5b(), test5c(), test5e(), test5f(), test5h(), and write_map().

int field = 0
 

Definition at line 230 of file ls.c.

unsigned char fieldwidth[MAXCOLS][MAXFLDS]
 

Definition at line 686 of file ls.c.

Referenced by print(), and print1().

struct file* filecol[MAXCOLS]
 

Definition at line 897 of file ls.c.

Referenced by columnise().

char flags[sizeof(allowed)]
 

Definition at line 105 of file ls.c.

int gid
 

Definition at line 77 of file ls.c.

struct idname * gids[NNAMES]
 

Referenced by idname().

int istty
 

Definition at line 79 of file ls.c.

char l_ifmt[] = "0pcCd?bB-?l?s???"
 

Definition at line 15 of file ls.c.

int ncols = 79
 

Definition at line 70 of file ls.c.

int nfiles
 

Definition at line 898 of file ls.c.

int nlines
 

Definition at line 898 of file ls.c.

int nsp = 0 [static]
 

Definition at line 717 of file ls.c.

Referenced by Pass2(), and print1().

char* path
 

Definition at line 197 of file ls.c.

int pidx = 0
 

Definition at line 198 of file ls.c.

int plen = 0
 

Definition at line 198 of file ls.c.

int(* rCMP)(struct file *f1, struct file *f2) [static]
 

Definition at line 448 of file ls.c.

Referenced by revcmp(), and sort().

int uid
 

Definition at line 77 of file ls.c.

struct idname * uids[NNAMES]
 

Referenced by idname().


Generated on Fri Apr 14 23:06:53 2006 for minix by  doxygen 1.4.6