/* $Copyright: $
* Copyright (c) 1996 - 2011 by Steve Baker (ice@mama.indstate.edu)
* All Rights reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "tree.h"
static char *version ="$Version: $ tree v1.6.0 (c) 1996 - 2011 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro $";
static char *hversion="\t\t tree v1.6.0 %s 1996 - 2011 by Steve Baker and Thomas Moore <br>\n"
"\t\t HTML output hacked and copyleft %s 1998 by Francesc Rocher <br>\n"
"\t\t Charsets / OS/2 support %s 2001 by Kyosuke Tokoro\n";
/* Globals */
bool dflag, lflag, pflag, sflag, Fflag, aflag, fflag, uflag, gflag;
bool qflag, Nflag, Qflag, Dflag, inodeflag, devflag, hflag, Rflag;
bool Hflag, siflag, cflag, Xflag, duflag, pruneflag;
bool noindent, force_color, nocolor, xdev, noreport, nolinks, flimit, dirsfirst, nosort;
char *pattern = NULL, *ipattern = NULL, *host = NULL, *title = "Directory Tree", *sp = " ";
char *timefmt = NULL;
const char *charset = NULL;
off_t (*listdir)(char *, int *, int *, u_long, dev_t) = unix_listdir;
int (*cmpfunc)() = alnumsort;
char *sLevel, *curdir, *outfilename = NULL;
FILE *outfile;
int Level, *dirs, maxdirs;
int mb_cur_max;
#ifdef __EMX__
const u_short ifmt[]={ FILE_ARCHIVED, FILE_DIRECTORY, FILE_SYSTEM, FILE_HIDDEN, FILE_READONLY, 0};
#else
#ifdef S_ISPORT
const u_int ifmt[] = {S_IFREG, S_IFDIR, S_IFLNK, S_IFCHR, S_IFBLK, S_IFSOCK, S_IFIFO, S_ISDOOR, S_ISPORT, 0};
const char fmt[] = "-dlcbspDP?";
const char *ftype[] = {"file", "directory", "link", "char", "block", "socket", "fifo", "door", "port", "unknown", NULL};
#else
const u_int ifmt[] = {S_IFREG, S_IFDIR, S_IFLNK, S_IFCHR, S_IFBLK, S_IFSOCK, S_IFIFO, 0};
const char fmt[] = "-dlcbsp?";
const char *ftype[] = {"file", "directory", "link", "char", "block", "socket", "fifo", "unknown", NULL};
#endif
#endif
/* Externs */
/* hash.c */
extern struct xtable *gtable[256], *utable[256];
extern struct inotable *itable[256];
/* color.c */
extern bool colorize, ansilines, linktargetcolor;
extern char *leftcode, *rightcode, *endcode;
extern const struct linedraw *linedraw;
int main(int argc, char **argv)
{
char **dirname = NULL;
int i,j=0,n,p,q,dtotal,ftotal,colored = FALSE;
struct stat st;
char sizebuf[64];
off_t size = 0;
mode_t mt;
q = p = dtotal = ftotal = 0;
aflag = dflag = fflag = lflag = pflag = sflag = Fflag = uflag = gflag = FALSE;
Dflag = qflag = Nflag = Qflag = Rflag = hflag = Hflag = siflag = cflag = FALSE;
noindent = force_color = nocolor = xdev = noreport = nolinks = FALSE;
dirsfirst = nosort = inodeflag = devflag = Xflag = FALSE;
duflag = pruneflag = FALSE;
flimit = 0;
dirs = xmalloc(sizeof(int) * (maxdirs=4096));
memset(dirs, 0, sizeof(int) * maxdirs);
dirs[0] = 0;
Level = -1;
setlocale(LC_CTYPE, "");
setlocale(LC_COLLATE, "");
charset = getcharset();
if (charset == NULL && patmatch(setlocale(LC_CTYPE,NULL), "*[Uu][Tt][Ff]-8") == 1) {
charset = "UTF-8";
}
/* Until I get rid of this hack, make it linux/cygwin/HP nonstop only: */
#if defined (LINUX) || defined (CYGWIN) || defined (__TANDEM)
mb_cur_max = (int)MB_CUR_MAX;
#else
mb_cur_max = 1;
#endif
memset(utable,0,sizeof(utable));
memset(gtable,0,sizeof(gtable));
memset(itable,0,sizeof(itable));
for(n=i=1;i<argc;i=n) {
n++;
if (argv[i][0] == '-' && argv[i][1]) {
for(j=1;argv[i][j];j++) {
switch(argv[i][j]) {
case 'N':
Nflag = TRUE;
break;
case 'q':
qflag = TRUE;
break;
case 'Q':
Qflag = TRUE;
break;
case 'd':
dflag = TRUE;
break;
case 'l':
lflag = TRUE;
break;
case 's':
sflag = TRUE;
break;
case 'h':
hflag = TRUE;
sflag = TRUE; /* Assume they also want -s */
break;
case 'u':
uflag = TRUE;
break;
case 'g':
gflag = TRUE;
break;
case 'f':
fflag = TRUE;
break;
case 'F':
Fflag = TRUE;
break;
case 'a':
aflag = TRUE;
break;
case 'p':
pflag = TRUE;
break;
case 'i':
noindent = TRUE;
break;
case 'C':
force_color = TRUE;
break;
case 'n':
nocolor = TRUE;
break;
case 'x':
xdev = TRUE;
break;
case 'P':
if (argv[n] == NULL) {
fprintf(stderr,"tree: missing argument to -P option.\n");
exit(1);
}
pattern = argv[n++];
break;
case 'I':
if (argv[n] == NULL) {
fprintf(stderr,"tree: missing argument to -I option.\n");
exit(1);
}
ipattern = argv[n++];
break;
case 'A':
ansilines = TRUE;
break;
case 'S':
charset = "IBM437";
break;
case 'D':
Dflag = TRUE;
break;
case 't':
cmpfunc = mtimesort;
break;
case 'c':
cmpfunc = ctimesort;
cflag = TRUE;
break;
case 'r':
cmpfunc = reversealnumsort;
break;
case 'v':
cmpfunc = versort;
break;
case 'U':
nosort = TRUE;
break;
case 'X':
Hflag = FALSE;
Xflag = TRUE;
break;
case 'H':
Hflag = TRUE;
Xflag = FALSE;
if (argv[n] == NULL) {
fprintf(stderr,"tree: missing argument to -H option.\n");
exit(1);
}
host = argv[n++];
sp = " ";
break;
case 'T':
if (argv[n] == NULL) {
fprintf(stderr,"tree: missing argument to -T option.\n");
exit(1);
}
title = argv[n++];
break;
case 'R':
Rflag = TRUE;
break;
case 'L':
if ((sLevel = argv[n++]) == NULL) {
fprintf(stderr,"tree: Missing argument to -L option.\n");
exit(1);
}
Level = strtoul(sLevel,NULL,0)-1;
if (Level < 0) {
fprintf(stderr,"tree: Invalid level, must be greater than 0.\n");
exit(1);
}
break;
case 'o':
if (argv[n] == NULL) {
fprintf(stderr,"tree: missing argument to -o option.\n");
exit(1);
}
outfilename = argv[n++];
break;
case '-':
if (j == 1) {
if (!strcmp("--help",argv[i])) usage(2);
if (!strcmp("--version",argv[i])) {
char *v = version+12;
printf("%.*s\n",(int)strlen(v)-1,v);
exit(0);
}
if (!strcmp("--inodes",argv[i])) {
j = strlen(argv[i])-1;
inodeflag=TRUE;
break;
}
if (!strcmp("--device",argv[i])) {
j = strlen(argv[i])-1;
devflag=TRUE;
break;
}
if (!strcmp("--noreport",argv[i])) {
j = strlen(argv[i])-1;
noreport = TRUE;
break;
}
if (!strcmp("--nolinks",argv[i])) {
j = strlen(argv[i])-1;
nolinks = TRUE;
break;
}
if (!strcmp("--dirsfirst",argv[i])) {
j = strlen(argv[i])-1;
dirsfirst = TRUE;
break;
}
if (!strncmp("--filelimit",argv[i],11)) {
j = 11;
if (*(argv[i]+11) == '=') {
if (*(argv[i]+12)) {
flimit=atoi(argv[i]+12);
j = strlen(argv[i])-1;
break;
}
}
if (argv[n] != NULL) {
flimit = atoi(argv[n++]);
j = strlen(argv[i])-1;
} else {
fprintf(stderr,"tree: missing argument to --filelimit\n");
exit(1);
}
break;
}
if (!strncmp("--charset",argv[i],9)){
j = 9;
if (*(argv[i]+j) == '=') {
if (*(charset = (argv[i]+10))) {
j = strlen(argv[i])-1;
break;
}
}
if (argv[n] != NULL) {
charset = argv[n++];
j = strlen(argv[i])-1;
} else {
initlinedraw(1);
exit(1);
}
break;
}
if (!strncmp("--si", argv[i], 4)) {
j = strlen(argv[i])-1;
sflag = TRUE;
hflag = TRUE;
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
tree-1.6.0.tgz (17个子文件)
tree-1.6.0
color.c 16KB
xml.c 9KB
hash.c 3KB
html.c 14KB
tree.h 5KB
TODO 2KB
LICENSE 18KB
CHANGES 9KB
unix.c 7KB
README 5KB
INSTALL 596B
strverscmp.c 5KB
doc
tree.1 10KB
tree.1.fr 7KB
xml.dtd 3KB
Makefile 3KB
tree.c 31KB
共 17 条
- 1
资源评论
diy534
- 粉丝: 61
- 资源: 62
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于SimPy和贝叶斯优化的流程仿真系统.zip
- (源码)基于Java Web的个人信息管理系统.zip
- (源码)基于C++和OTL4的PostgreSQL数据库连接系统.zip
- (源码)基于ESP32和AWS IoT Core的室内温湿度监测系统.zip
- (源码)基于Arduino的I2C协议交通灯模拟系统.zip
- coco.names 文件
- (源码)基于Spring Boot和Vue的房屋租赁管理系统.zip
- (源码)基于Android的饭店点菜系统.zip
- (源码)基于Android平台的权限管理系统.zip
- (源码)基于CC++和wxWidgets框架的LEGO模型火车控制系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功