/* $Copyright: $
* Copyright (c) 1996 - 2014 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.7.0 (c) 1996 - 2014 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro $";
static char *hversion="\t\t tree v1.7.0 %s 1996 - 2014 by Steve Baker and Thomas Moore <br>\n"
"\t\t HTML output hacked and copyleft %s 1998 by Francesc Rocher <br>\n"
"\t\t JSON output hacked and copyleft %s 2014 by Florian Sesser <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, Jflag, duflag, pruneflag;
bool noindent, force_color, nocolor, xdev, noreport, nolinks, flimit, dirsfirst;
bool ignorecase, matchdirs;
bool reverse;
char *pattern = NULL, *ipattern = NULL, *host = NULL, *title = "Directory Tree", *sp = " ", *_nl = "\n";
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_IFPORT
const u_int ifmt[] = {S_IFREG, S_IFDIR, S_IFLNK, S_IFCHR, S_IFBLK, S_IFSOCK, S_IFIFO, S_IFDOOR, S_IFPORT, 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
struct sorts {
char *name;
int (*cmpfunc)();
} sorts[] = {
{"name", alnumsort},
{"version", versort},
{"size", fsizesort},
{"mtime", mtimesort},
{"ctime", ctimesort},
{NULL, NULL}
};
/* 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,k,n,optf,p,q,dtotal,ftotal,colored = FALSE;
struct stat st;
char sizebuf[64], *stmp;
off_t size = 0;
mode_t mt;
bool needfulltree;
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 = reverse = FALSE;
ignorecase = matchdirs = dirsfirst = inodeflag = devflag = Xflag = Jflag = 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 && strcmp(nl_langinfo(CODESET), "UTF-8") == 0) {
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));
optf = TRUE;
for(n=i=1;i<argc;i=n) {
n++;
if (optf && 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;
_nl = "";
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':
reverse = TRUE;
break;
case 'v':
cmpfunc = versort;
break;
case 'U':
cmpfunc = NULL;
break;
case 'X':
Hflag = FALSE;
Xflag = TRUE;
break;
case 'J':
Jflag = 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("--", argv[i])) {
optf = FALSE;
break;
}
if (!strcmp("--help",argv[i])) {
usage(2);
exit(0);
}
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(arg
mylife512
- 粉丝: 1465
- 资源: 1万+
最新资源
- 基于Go-micro微服务的秒杀系统详细文档+优秀项目+全部资料.zip
- 基于golang实现在线客服系统,包含用户端(h5,微信小程序),客服端(PC),方便跟已有的系统整合。适用于小程序自带的客服系统无法满足或有多端业务需求的情况详细文档+优秀项目+全部资料.zip
- 基于gorillawebsocket封装的websocket库,实现基于系统维度的消息推送,基于群组维度的消息推送,基于单个和多个客户端消息推送详细文档+优秀项目+全部资料.zip
- 基于Go-Zero + Vue3 + TypeScript + Element-Plus开发的简单高效权限管理系统详细文档+优秀项目+全部资料.zip
- 基于Go-Zero Nestjs + Vue3 + TypeScript + Element-Plus开发的简单高效权限管理系统详细文档+优秀项目+全部资料.zip
- linux常用命令大全.txt
- 基于go-zero的影票售卖系统详细文档+优秀项目+全部资料.zip
- 基于Go-Zero + vue-element-admin的前后端分离微服务管理系统的前端模块详细文档+优秀项目+全部资料.zip
- 基于go-zero 框架实现的电商系统的后端服务详细文档+优秀项目+全部资料.zip
- 基于go-zero实现的网盘系统详细文档+优秀项目+全部资料.zip
- 基于go-zero框架数据中台系统详细文档+优秀项目+全部资料.zip
- 基于go-zero和gorm开发的分布式微服务后端权限管理系统脚手架。十分合适新手入手go-zero、gorm、casbin、jwt等。详细文档+优秀项目+全部
- 基于Go的WebSocket直播间推送系统详细文档+优秀项目+全部资料.zip
- 基于Go和GraphQL的微型进销存系统:服务器端(基于Golang,GraphQL,GORM,jwt-go等开发)详细文档+优秀项目+全部资料.zip
- 基于go的自托管博客系统详细文档+优秀项目+全部资料.zip
- 基于go开发的分布式高并发web电商系统详细文档+优秀项目+全部资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈