📄 wardirfmtunixls.cpp
字号:
#include "StdAfx.h"#include "WarDirfmtUnixLs.h" // class implemented#ifndef WAR_FSTREAM_INCLUDED# define WAR_FSTREAM_INCLUDED# include <fstream>#endif#ifndef WAR_SSTREAM_INCLUDED# define WAR_SSTREAM_INCLUDED# include <sstream>#endif/////////////////////////////// PUBLIC ///////////////////////////////////////WAR_CPPT_IMPL WarDirfmtUnixLs<std::ofstream>;//============================= LIFECYCLE ====================================template <class outputT> WarDirfmtUnixLs<outputT>::WarDirfmtUnixLs<outputT>(): mDoPrintBlockSize(false),mDoPrintInodes(false),mDoPrintBlockSizeAll(false),mDoNumericIds(false),mDoHideGroup(false),mDoFullTime(false),mDoAllFiles(false),mDoReallyAllFiles(false),mDoRecursive(false),mDoPrintDirName(false),mDoImmediateDirs(false),mDoQmarkFunnyChars(false),mDoReverseSort(false),mDoTraceLinks(false),mListFormat(LONG_FORMAT),mSortBy(SORT_NAME),mTimeType(TIME_MTIME),mIndicatorStyle(IS_NONE),mOutputBlockSize(0),mDoQuoteNames(false),mpDir(NULL){ strcpy(mEndOfLine, "\n");}template <class outputT>WarDirfmtUnixLs<outputT>::~WarDirfmtUnixLs(){};//============================= OPERATORS ====================================//============================= OPERATIONS ===================================template <class outputT>outputT& WarDirfmtUnixLs<outputT>::List (outputT& Out, const WarSvrDirList& Dir){ mpDir = &Dir; if ((LONG_FORMAT == mListFormat) || mDoPrintBlockSize) { if (mDoPrintDirName) Out << mEndOfLine << Dir.GetRelativePath() << ":" << mEndOfLine; Out << "total " << Dir.GetBlocks() << mEndOfLine; } if (mSortBy == SORT_NAME) DoNameSort(Out, Dir); else DoOtherSort(Out, Dir); mpDir = NULL; mDoPrintDirName = true; // In case there are more dirs... return Out;}template <class outputT>void WarDirfmtUnixLs<outputT>::ParseArgs(int argc, char **argv, seq_file_list_t& List){ WarGetopt my_opts; static const struct option options[] = { {"all",no_argument, 0, 'a'}, // {"escape",no_argument, 0, 'b'}, {"directory",no_argument, 0, 'd'}, // {"dired",no_argument, 0, 'D'}, {"full-time",no_argument, 0, 1}, // NB m_bFullTime {"human-readable",no_argument, 0, 'h'}, {"inode",no_argument, 0, 'i'}, {"kilobytes",no_argument, 0, 'k'}, {"numeric-uid-gid",no_argument, 0, 'n'}, {"no-group",no_argument, 0, 'G'}, {"hide-control-chars",no_argument, 0, 'q'}, {"reverse",no_argument, 0, 'r'}, {"size",no_argument, 0, 's'}, {"width",required_argument, 0, 'w'}, {"almost-all",no_argument, 0, 'A'}, {"ignore-backups",no_argument, 0, 'B'}, {"classify",no_argument, 0, 'F'}, {"file-type",no_argument, 0, 'p'}, {"si",no_argument, 0, 'H'}, {"ignore",required_argument, 0, 'I'}, {"indicator-style",required_argument, 0, 14}, {"dereference",no_argument, 0, 'L'}, {"literal",no_argument, 0, 'N'}, {"quote-name",no_argument, 0, 'Q'}, // {"quoting-style",required_argument, 0, 15}, {"recursive",no_argument, 0, 'R'}, {"format",required_argument, 0, 12}, {"show-control-chars",no_argument, 0, 16}, {"sort",required_argument, 0, 10}, // {"tabsize",required_argument, 0, 'T'}, {"time",required_argument, 0, 11}, {"color",optional_argument, 0, 13}, {"block-size",required_argument, 0, 17}, {"help",no_argument, 0, 250}, {"version",no_argument, 0, 251}, {NULL, 0, NULL, 0} }; int c = 0; while ((c = my_opts.GetoptLong(argc, argv, "acdefghiklmnoqrstuvw:xABCFGHI:LNRSUX1", options, NULL)) > 0) { switch (c) { case 'a': mDoAllFiles = true; mDoReallyAllFiles = true; break; // case 'b': // set_quoting_style (NULL, escape_quoting_style); // break; case 'c': mTimeType = TIME_CTIME; mSortBy = SORT_TIME; break; case 'd': mDoImmediateDirs = true; break; case 'f': /* Same as enabling -a -U and disabling -l -s. */ mDoAllFiles = 1; mDoReallyAllFiles = 1; mSortBy = SORT_NONE; /* disable -l */ if (mListFormat == LONG_FORMAT) mListFormat = ONE_PER_LINE; mDoPrintBlockSize = false; /* disable -s */ break; case 'g': /* No effect. For BSD compatibility. */ break; case 'h': mOutputBlockSize = -1024; break; case 'H': mOutputBlockSize = -1000; break; case 'i': mDoPrintInodes = true; break; case 'k': mOutputBlockSize = 1024; break; case 'l': mListFormat = LONG_FORMAT; break; case 'm': mListFormat = WITH_COMMAS; break; case 'n': mDoNumericIds = 1; break; case 'o': /* Just like -l, but don't display group info. */ mListFormat = LONG_FORMAT; mDoHideGroup = true; break; case 'p': mIndicatorStyle = IS_FILE_TYPE; break; case 'q': mDoQmarkFunnyChars = true; break; case 'r': mDoReverseSort = 1; break; case 's': mDoPrintBlockSizeAll = 1; break; case 't': mSortBy = SORT_TIME; break; case 'u': mSortBy = SORT_TIME; mTimeType = TIME_ATIME; break; case 'v': mSortBy = SORT_VERSION; break; case 'w': // Ignore break; case 'x': mListFormat = HORIZONTAL; break; case 'A': mDoReallyAllFiles = 0; mDoAllFiles = 1; break; case 'B': mIgnorePatterns.push_back("*~"); mIgnorePatterns.push_back(".*~"); break; case 'C': mListFormat = MANY_PER_LINE; break; // case 'D': // dired = 1; // break; case 'F': mIndicatorStyle = IS_CLASSIFY; break; case 'G': /* inhibit display of group info */ mDoHideGroup = 1; break; case 'I': mIgnorePatterns.push_back(my_opts.optarg); break; case 'L': mDoTraceLinks = true; break; // case 'N': // set_quoting_style (NULL, literal_quoting_style); // break; case 'Q': mDoQuoteNames = true; break; case 'R': mDoRecursive = true; break; case 'S': mSortBy = SORT_SIZE; break; // case 'T': // break; case 'U': mSortBy = SORT_NONE; break; case 'X': mSortBy = SORT_EXTENSION; break; case '1': mListFormat = ONE_PER_LINE; break; case 10: /* --sort */ if (!strcmp(my_opts.optarg, "none")) mSortBy = SORT_NONE; else if (!strcmp(my_opts.optarg, "time")) mSortBy = SORT_TIME; else if (!strcmp(my_opts.optarg, "extension")) mSortBy = SORT_EXTENSION; else if (!strcmp(my_opts.optarg, "version")) mSortBy = SORT_VERSION; break; case 11: /* --time */ if (!strcmp(my_opts.optarg, "atime")) mTimeType = TIME_ATIME; if (!strcmp(my_opts.optarg, "access")) mTimeType = TIME_ATIME; if (!strcmp(my_opts.optarg, "use")) mTimeType = TIME_ATIME; if (!strcmp(my_opts.optarg, "ctime")) mTimeType = TIME_CTIME; if (!strcmp(my_opts.optarg, "status")) mTimeType = TIME_CTIME; break; case 12: /* --format */ if (!strcmp(my_opts.optarg, "verbose")) mListFormat = LONG_FORMAT; if (!strcmp(my_opts.optarg, "long")) mListFormat = LONG_FORMAT; if (!strcmp(my_opts.optarg, "commas")) mListFormat = WITH_COMMAS; if (!strcmp(my_opts.optarg, "HORIZONTAL")) mListFormat = HORIZONTAL; if (!strcmp(my_opts.optarg, "across")) mListFormat = LONG_FORMAT; if (!strcmp(my_opts.optarg, "vertical")) mListFormat = MANY_PER_LINE; if (!strcmp(my_opts.optarg, "single-column")) mListFormat = ONE_PER_LINE; break; case 13: /* --color */ // Just ignore break; case 14: /* --indicator-style */ if (!strcmp(my_opts.optarg, "none")) mIndicatorStyle = IS_NONE; if (!strcmp(my_opts.optarg, "classify")) mIndicatorStyle = IS_CLASSIFY; if (!strcmp(my_opts.optarg, "file_type")) mIndicatorStyle = IS_FILE_TYPE; break; // case 15: /* --quoting-style */ // break; case 16: mDoQmarkFunnyChars = false; break; case 17: mOutputBlockSize = atoi( my_opts.optarg ? my_opts.optarg : "0"); break; case 250: Usage(); case 251: mErrorMessage = "WarDirfmtUnixLs v. 3.0/Generic"; mErrorMessage += mEndOfLine; WarThrow(WarError(WAR_ERR_VERSION), NULL); } } for (;my_opts.optind < argc; my_opts.optind++) List.push_back(argv[my_opts.optind]);} template <class outputT>void WarDirfmtUnixLs<outputT>::Usage() throw (WarException){ std::ostringstream buf; buf << "Usage: ls [OPTION]... [FILE]... " << mEndOfLine; buf << "In FTP servers: LIST [OPTION]... [FILE]" << mEndOfLine; buf << "List information about the FILEs (the current directory by default)." << mEndOfLine; buf << "Sort entries alphabetically if none of -cftuSUX nor --sort." << mEndOfLine; buf << mEndOfLine; buf << "-a, --all do not hide entries starting with ." << mEndOfLine; buf << "-A, --almost-all do not list implied . and .." << mEndOfLine; //buf << "-b, --escape print octal escapes for nongraphic characters" << mEndOfLine; buf << " --block-size=SIZE use SIZE-byte blocks" << mEndOfLine; buf << "-B, --ignore-backups do not list implied entries ending with ~" << mEndOfLine; buf << "-c sort by change time; with -l: show ctime" << mEndOfLine; buf << "-C list entries by columns" << mEndOfLine; //buf << " --color[=WHEN] control whether color is used to distinguish file" << mEndOfLine; buf << " types. WHEN may be `never', `always', or `auto'" << mEndOfLine; buf << "-d, --directory list directory entries instead of contents" << mEndOfLine; //buf << "-D, --dired generate output designed for Emacs' dired mode" << mEndOfLine; buf << "-f do not sort, enable -aU, disable -lst" << mEndOfLine; buf << "-F, --classify append indicator (one of */=@|) to entries" << mEndOfLine; buf << " --format=WORD across -x, commas -m, HORIZONTAL -x, long -l," << mEndOfLine; buf << " single-column -1, verbose -l, vertical -C" << mEndOfLine; buf << " --full-time list both full date and full time\n"; buf << "-g (ignored)" << mEndOfLine; buf << "-G, --no-group inhibit display of group information" << mEndOfLine; buf << "-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)" << mEndOfLine; buf << "-H, --si likewise, but use powers of 1000 not 1024" << mEndOfLine; buf << " --indicator-style=WORD append indicator with style WORD to entry names:" << mEndOfLine; buf << " none (default), classify (-F), file-type (-p)" << mEndOfLine; buf << "-i, --inode print index number of each file" << mEndOfLine;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -