/* $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;
diy534
- 粉丝: 61
- 资源: 62
最新资源
- C# Winform简单的俄罗斯方块小游戏源码2.zip
- 混合动力汽车动态规划算法理论油耗计算与视频教学,使用matlab编写快速计算程序,整个工程结构模块化,可以快速改为串联,并联,混联等 控制量可以快速扩展为档位,转矩,转速等 状态量一般为SOC,目
- 全国职业院校技能大赛网络建设与运维规程
- agv 1223.fbx
- 考虑泄流效应的光伏无功优化matlab 以IEEE33节点为例,分析泄流效应下,最佳网络无功补偿方案,程序运行稳定
- jetbra插件工具,方便开发者快速开发
- 云计算2401班课程设计资料.zip
- 企业宣传PPT模板, 企业宣传PPT模板
- 微环谐振腔的光学频率梳matlab仿真 微腔光频梳仿真 包括求解LLE方程(Lugiato-Lefever equation)实现微环中的光频梳,同时考虑了色散,克尔非线性,外部泵浦等因素,具有可延展
- 生菜生长记录数据集.zip
- 基于Springboot+Vue健身房管理系统-毕业源码案例设计(高分项目).zip
- 中国风格, 节日 主题, PPT模板
- lcd取模工具,很难找的有用的LCD显示开发工具
- 基于Springboot+Vue健身房管理系统-毕业源码案例设计(源码+数据库).zip
- 基于Springboot+Vue江理工文档管理系统的设计与实现-毕业源码案例设计(源码+论文).zip
- 基于Springboot+Vue教师工作量管理系统-毕业源码案例设计(高分毕业设计).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈