ls.rar

  • PUDN用户
    了解作者
  • Unix_Linux
    开发工具
  • 7KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2015-11-26 21:36
    上传日期
list file or directory define DOTSUP to suppress listing of files beginning with dot.
ls.rar
  • ls.c
    21.8KB
内容介绍
#ifndef lint static char sccsid[] = "@(#)ls.c 1.1 92/07/30 SMI"; /* from S5R2 1.19 */ #endif /* * list file or directory; * define DOTSUP to suppress listing of files beginning with dot */ #include <sys/param.h> #include <sys/types.h> #include <sys/sysmacros.h> #include <sys/stat.h> #include <sys/dir.h> #include <stdio.h> #if u3b #include <sys/macro.h> #endif #include <ctype.h> #include <locale.h> #ifndef STANDALONE #define TERMINFO #endif /* -DNOTERMINFO can be defined on the cc command line to prevent * the use of terminfo. This should be done on systems not having * the terminfo feature (pre 6.0 sytems ?). * As a result, columnar listings assume 80 columns for output, * unless told otherwise via the COLUMNS environment variable. */ #ifdef NOTERMINFO #undef TERMINFO #endif #ifdef TERMINFO #include <curses.h> #include <term.h> #endif #define DOTSUP 1 #define ISARG 0100000 /* this bit equals 1 in lflags of structure lbuf * if name is an argument to ls; */ #define DIRECT 10 /* Number of direct blocks */ struct lbuf { char ltype; /* file type, e.g. 'd', 'c', 'f' */ ino_t lnum; /* inode number of file */ short lflags; /* 0777 bits used as r,w,x permissions */ short lnl; /* number of links to file */ unsigned short luid; /* owner id */ unsigned short lgid; /* group id */ long lsize; /* file size or major/minor dev numbers */ long lblks; /* number of blocks used */ long lmtime; /* time (modify or access or create) */ char *lname; /* for filename in directory or name in ls-command */ char *llinkto; /* symbolic link value */ }; struct dchain { char *dc_name; /* path name */ struct dchain *dc_next; /* next directory in the chain */ }; struct dchain *dfirst; /* start of the dir chain */ struct dchain *cdfirst; /* start of the durrent dir chain */ struct dchain *dtemp; /* temporary - used for linking */ char *curdir; /* the current directory */ int nfiles = 0; /* number of flist entries in current use */ int nargs = 0; /* number of flist entries used for arguments */ int maxfils = 0; /* number of flist/lbuf entries allocated */ int maxn = 0; /* number of flist entries with lbufs assigned */ int quantn = 1024; /* allocation growth quantum */ struct lbuf *nxtlbf; /* pointer to next lbuf to be assigned */ struct lbuf **flist; /* pointer to list of lbuf pointers */ struct lbuf *gstat(); FILE *pwdfu, *pwdfg; int aflg, bflg, cflg, dflg, fflg, gflg, iflg, lflg, mflg; int nflg, oflg, pflg, qflg, sflg, tflg, uflg, xflg; int Cflg, Fflg, Lflg, Rflg; int rflg = 1; /* initialized to 1 for special use in compar() */ int flags; int err = 0; /* Contains return code */ char *dmark; /* Used if -p option active. Contains "/" or NULL. */ unsigned lastuid = -1, lastgid = -1; int statreq; /* is > 0 if any of sflg, (n)lflg, tflg are on */ static int nomocore = 0; char *dotp = "."; char *makename(); char *getname(), *getgroup(); char *ctime(), *strcpy(); long tblocks; /* total number of blocks of files in a directory */ long year, now; int num_cols = 80; int colwidth; int filewidth; int fixedwidth; int curcol; int compar(); main(argc, argv) int argc; char *argv[]; { extern char *optarg; extern int optind; int amino, opterr=0; int c; register struct lbuf *ep; struct lbuf lb; int i, width; long time(); char *malloc(); void qsort(), exit(); #ifdef STANDALONE if (argv[0][0] == '\0') argc = getargv("ls", &argv, 0); #endif setlocale(LC_ALL, ""); /* get local environment */ lb.lmtime = time((long *) NULL); year = lb.lmtime - 6L*30L*24L*60L*60L; /* 6 months ago */ now = lb.lmtime + 60; while ((c=getopt(argc, argv, "RadCxmnlogrtucpFbqisfL")) != EOF) switch(c) { case 'R': Rflg++; statreq++; continue; case 'a': aflg++; continue; case 'd': dflg++; continue; case 'C': Cflg = 1; mflg = 0; continue; case 'x': xflg = 1; Cflg = 1; mflg = 0; continue; case 'm': Cflg = 0; mflg = 1; continue; case 'n': nflg++; case 'l': lflg++; statreq++; continue; case 'o': oflg++; lflg++; statreq++; continue; case 'g': gflg++; lflg++; statreq++; continue; case 'r': rflg = -1; continue; case 't': tflg++; statreq++; continue; case 'u': uflg++; continue; case 'c': cflg++; continue; case 'p': pflg++; statreq++; continue; case 'F': Fflg++; statreq++; continue; case 'b': bflg = 1; qflg = 0; continue; case 'q': qflg = 1; bflg = 0; continue; case 'i': iflg++; continue; case 's': sflg++; statreq++; continue; case 'f': fflg++; continue; case 'L': Lflg++; continue; case '?': opterr++; continue; } if(opterr) { fprintf(stderr,"usage: ls -RadCxmnlogrtucpFbqisfL [files]\n"); exit(2); } if (fflg) { aflg++; lflg = 0; sflg = 0; tflg = 0; statreq = 0; } fixedwidth = 2; if (pflg || Fflg) fixedwidth++; if (iflg) fixedwidth += 6; if (sflg) fixedwidth += 5; if (lflg) { /* This is the way */ if (!gflg && !oflg) /* 5.0 behaved, but */ gflg = oflg = 1; /* it may be open */ else /* to interpretation*/ if (gflg && oflg) gflg = oflg = 0; Cflg = mflg = 0; } if (Cflg || mflg) { char *getenv(); char *clptr; if ((clptr = getenv("COLUMNS")) != NULL) num_cols = atoi(clptr); #ifdef TERMINFO else { setupterm(0,1,&i); /* get term description */ resetterm(); /* undo what setupterm changed */ if (i == 1) num_cols = columns; } #endif if (num_cols < 20 || num_cols > 160) /* assume it is an error */ num_cols = 80; } /* allocate space for flist and the associated */ /* data structures (lbufs) */ maxfils = quantn; if((flist=(struct lbuf **)malloc((unsigned)(maxfils * sizeof(struct lbuf *)))) == NULL || (nxtlbf = (struct lbuf *)malloc((unsigned)(quantn * sizeof(struct lbuf)))) == NULL) { fprintf(stderr, "ls: out of memory\n"); exit(2); } if ((amino=(argc-optind))==0) { /* case when no names are given * in ls-command and current * directory is to be used */ argv[optind] = dotp; } for (i=0; i < (amino ? amino : 1); i++) { if (Cflg || mflg) { width = strlen(argv[optind]); if (width > filewidth) filewidth = width; } if ((ep = gstat((*argv[optind] ? argv[optind] : dotp), 1))==NULL) { err = 2; optind++; continue; } ep->lname = (*argv[optind] ? argv[optind] : dotp); ep->lflags |= ISARG; optind++; nargs++; /* count good arguments stored in flist */ } colwidth = fixedwidth + filewidth; qsort(flist, (unsigned)nargs, sizeof(struct lbuf *), compar); for (i=0; i<nargs; i++) if (flist[i]->ltype=='d' && dflg==0 || fflg) break; pem(&flist[0],&flist[i], 0); for (; i<nargs; i++) { pdirectory(flist[i]->lname, (amino>1), nargs); /* -R: print subdirectories found */ while (dfirst || cdfirst) { /* Place direct subdirs on front in right order */ while (cdfirst) { /* reverse cdfirst onto front of dfirst */ dtemp = cdfirst; cdfirst = cdfirst -> dc_next; dtemp -> dc_next = dfirst; dfirst = dtemp; } /* take off first dir on dfirst & print it */ dtemp = dfirst; dfirst = dfirst->dc_next; pdirectory (dtemp->dc_name, 1, nargs); free (dtemp->dc_name); free ((char *)dtemp); } } exit(err); /*NOTREACHED*/ } /* * pdirectory: print the directory name, labelling it if title is * nonzero, using lp as the place to start reading in the dir. */ pdirectory (name, title, lp) char *name; int title; int lp; { register struct dchain *dp; register struct lbuf *ap; register char *pname; register int j; filewidth = 0; curdir = name; if (title) { putc('\n', stdout); pprintf(name); putc(':', stdout); curcol++; new_line(); } nfiles = lp; rddir(name); if (fflg==0) qsort(&flist[lp],(unsigned)(nfiles - lp),sizeof(struct lbuf *),compar); if (Rflg) for (j = nfiles - 1; j >= lp; j--) {
评论
    相关推荐
    • DoT.rar
      MUSIC谱分解算法,For the MUSIC decomposition pseudospectrum PMUSIC(θ) where M = 6, d = λ/2, Set the vertical scale to be ?30 to 5 dB and horizontal scale to be ?85? to 85?.
    • DOT.zip
      vhdl code for DOT matrix
    • dot.rar
      ADAPTIVETHRESHOLD An adaptive thresholding algorithm that se
    • dot.zip
      c语言控制51单片机在16*16的点阵屏上显示文字
    • DOT.rar
      能用的1个MT4指标,大家放心使用,免费下载
    • immutability_dot.rar
      skinsharp皮肤设计软件,专业的易语言版本
    • dot.rar
      Tests regular expressions containing.
    • dot.rar
      從上到下掃描顯示綠色或紅色,同時亮的話顯示橘色
    • dot.zip
      VideoComm视频通信控件适用于VC++,VB,dot Net平台,C++Builder,Delphi,易语言,网页应
    • dot.rar
      2001年的程序设计大赛的题目我觉得比较难没有做出来!