📄 wardirfmtunixls.cpp
字号:
buf << "-I, --ignore=PATTERN do not list implied entries matching shell PATTERN" << mEndOfLine; buf << "-k, --kilobytes like --block-size=1024" << mEndOfLine; buf << "-l use a long listing format" << mEndOfLine; buf << "-L, --dereference list entries pointed to by symbolic links" << mEndOfLine; buf << "-m fill width with a comma separated list of entries" << mEndOfLine; buf << "-n, --numeric-uid-gid list numeric UIDs and GIDs instead of names" << mEndOfLine; buf << "-N, --literal print raw entry names (don't treat e.g. control" << mEndOfLine; buf << " characters specially)" << mEndOfLine; buf << "-o use long listing format without group info" << mEndOfLine; buf << "-p, --file-type append indicator (one of /=@|) to entries" << mEndOfLine; buf << "-q, --hide-control-chars print ? instead of non graphic characters" << mEndOfLine; buf << " --show-control-chars show non graphic characters as-is (default)" << mEndOfLine; buf << "-Q, --quote-name enclose entry names in double quotes" << mEndOfLine; //buf << " --quoting-style=WORD use quoting style WORD for entry names:" << mEndOfLine; //buf << " literal, shell, shell-always, c, escape" << mEndOfLine; buf << "-r, --reverse reverse order while sorting" << mEndOfLine; buf << "-R, --recursive list subdirectories recursively" << mEndOfLine; buf << "-s, --size print size of each file, in blocks\n"; buf << "-S sort by file size" << mEndOfLine; buf << " --sort=WORD extension -X, none -U, size -S, time -t," << mEndOfLine; buf << " version -v" << mEndOfLine; buf << " status -c, time -t, atime -u, access -u, use -u" << mEndOfLine; buf << " --time=WORD show time as WORD instead of modification time:" << mEndOfLine; buf << " atime, access, use, ctime or status; use" << mEndOfLine; buf << " specified time as sort key if --sort=time" << mEndOfLine; buf << "-t sort by modification time" << mEndOfLine; //buf << "-T, --tabsize=COLS assume tab stops at each COLS instead of 8" << mEndOfLine; buf << "-u sort by last access time; with -l: show atime" << mEndOfLine; buf << "-U do not sort; list entries in directory order" << mEndOfLine; buf << "-v sort by version" << mEndOfLine; buf << "-w, --width=COLS assume screen width instead of current value" << mEndOfLine; buf << "-x list entries by lines instead of by columns" << mEndOfLine; buf << "-X sort alphabetically by entry extension" << mEndOfLine; buf << "-1 list one file per line" << mEndOfLine; buf << " --help display this help and exit" << mEndOfLine; buf << " --version output version information and exit" << mEndOfLine; buf << '\0'; mErrorMessage = buf.str(); WarThrow(WarError(WAR_ERR_USAGE), NULL);}template <class outputT>void WarDirfmtUnixLs<outputT>::InvalidPath(const std::string& path){}template <class outputT>void WarDirfmtUnixLs<outputT>::ExportExcludelist(WarDirList::patterns_t& excludeList){ for(ignore_patterns_t::const_iterator P = mIgnorePatterns.begin() ; P != mIgnorePatterns.end() ; P++) { excludeList.push_back(war_svrpath_t(WarUtf8(P->c_str()).GetUnicode().c_str())); }}//============================= CALLBACK ===================================//============================= ACCESS ===================================//============================= INQUIRY ===================================template <class outputT>int WarDirfmtUnixLs<outputT>::ExportFlags(){ int my_flags = DIRF_TRY_SAFE_PATTERNS; if (mDoRecursive) my_flags|= DIRF_RECURSIVE; if (!mDoReallyAllFiles) my_flags|= DIRF_HIDE_DOT_DOTDOT; if (!mDoReallyAllFiles || !mDoAllFiles) my_flags|= DIRF_HIDE_DOT_FILES; return my_flags;}/////////////////////////////// PROTECTED ////////////////////////////////////////////////////////////////// PRIVATE ///////////////////////////////////template <class outputT>void WarDirfmtUnixLs<outputT>::DoNameSort(outputT& Out, const WarDirList& Dir){ for(WarDirList::nodelist_t::const_iterator P = Dir.GetList().begin() ; P != Dir.GetList().end() ; P++) { OutNode(Out, P->Data()); } //Out << (war_ccstr_t)Buffer;}template <class outputT>void WarDirfmtUnixLs<outputT>::DoOtherSort(outputT& Out, const WarDirList& Dir){ assert(false);}template <class outputT>void WarDirfmtUnixLs<outputT>::OutNode(outputT& Out, const WarDirListNode& Node){ if (Node.mType > WarDirListNode::FT_LINK) return; // Hidden switch(mListFormat) { case LONG_FORMAT: OutLong(Out, Node); break; case ONE_PER_LINE: OutShort(Out, Node); break; case MANY_PER_LINE: case HORIZONTAL: case WITH_COMMAS: assert(false); }}template <class outputT>void WarDirfmtUnixLs<outputT>::OutShort(outputT& Out, const WarDirListNode& Node){ OutNameAndStuff(Out, Node); Out << mEndOfLine;}template <class outputT>void WarDirfmtUnixLs<outputT>::OutNameAndStuff(outputT& Out, const WarDirListNode& Node){ if (mDoPrintInodes) OutInode(Out, Node); if (mDoPrintBlockSizeAll) OutBlocksize(Out, Node); OutQuotedName(Out, Node);}template <class outputT>void WarDirfmtUnixLs<outputT>::OutQuotedName(outputT& Out, const WarDirListNode& Node){ if (mDoQuoteNames) { Out << '\"'; Out << WarEscapeStr<char>(Node.mName, '\"'); Out << '\"'; } else Out << Node.mName; char my_indicator = 0; switch(mIndicatorStyle) { case IS_NONE: break; case IS_CLASSIFY: if (WAR_ISREG(Node)) { if (Node.mMode & (S_IXUSR | S_IXGRP | S_IXOTH)) my_indicator = '*'; break; } // Fall trough case IS_FILE_TYPE: if (WAR_ISDIR (Node)) my_indicator = '/'; else if (WAR_ISLNK (Node)) my_indicator = '@'; else if (WAR_ISFIFO (Node)) my_indicator = '|'; else if (WAR_ISSOCK (Node)) my_indicator = '='; else if (WAR_ISDOOR (Node)) my_indicator = '>'; break; } if (my_indicator) Out << my_indicator;}template <class outputT>void WarDirfmtUnixLs<outputT>::OutLong(outputT& Out, const WarDirListNode& Node){ static const char spaces[] = {" "}; OutMode(Out, Node); if (mDoPrintInodes) OutInode(Out, Node); if (mDoPrintBlockSizeAll) OutBlocksize(Out, Node); OutLinks(Out, Node); std::string user_name /* = (mDoNumericIds ? "" : GetUser(Node.mUid))*/; if (user_name.empty()) WarItoa(user_name, Node.mUid); if (user_name.length() < 8) user_name += &spaces[user_name.length() % 8]; else user_name.erase(8); Out << user_name; if (!mDoHideGroup) { std::string group_name /*= (mDoNumericIds ? "" : GetGroup(Node.mGid))*/; if (group_name.empty()) WarItoa(group_name, Node.mGid); if (group_name.length() < 8) group_name += &spaces[group_name.length() % 8]; else group_name.erase(8); Out << group_name; } OutLength(Out, Node); OutDate(Out, Node); OutQuotedName(Out, Node); Out << mEndOfLine;}template <class outputT>void WarDirfmtUnixLs<outputT>::OutLength(outputT& Out, const WarDirListNode& Node){ OutHumanDigit(Out, Node.mSize, 8);}template <class outputT>void WarDirfmtUnixLs<outputT>::OutHumanDigit(outputT& Out, const war_flen_t value, size_t colWidth){ static const char *suffixes[] = { "", /* not used */ "k", /* kilo */ "M", /* Mega */ "G", /* Giga */ "T", /* Tera */ "P", /* Peta */ "E", /* Exa */ "Z", /* Zetta */ "Y" /* Yotta */ }; if (0 > mOutputBlockSize) mOutputBlockSize *= -1; if ((0 == mOutputBlockSize) || (value < mOutputBlockSize)) { // Most common situation, do it fast and easy! char buffer[32]; if ((value <= ULONG_MAX) && (sizeof(buffer) > colWidth)) { sprintf(buffer, "%*u ", colWidth, (unsigned)value); Out << buffer; return; } else { std::string buffer; Out << WarItoa(buffer, value); return; } } std::string buffer; double blockszie_in_power = mOutputBlockSize, next_power = 0; for(size_t power = 1; power < sizeof(suffixes); power++) { if (value < (next_power = (blockszie_in_power * mOutputBlockSize))) { char buf[512]; double human_value = (double)(value) / blockszie_in_power; if (10 > human_value) sprintf(buf, "%*.1lf%s ", colWidth -1, human_value, suffixes[power]); else sprintf(buf, "%*.0lf%s ", colWidth -1, human_value, suffixes[power]); Out << buf; return; } blockszie_in_power = next_power; } Out << "########";}template <class outputT>void WarDirfmtUnixLs<outputT>::OutInode(outputT& Out, const WarDirListNode& Node){ char buffer[16]; sprintf(buffer, "%*ld ", INODE_DIGITS, Node.mInode); Out << buffer;}template <class outputT>void WarDirfmtUnixLs<outputT>::OutBlocksize(outputT& Out, const WarDirListNode& Node){ char buffer[16]; sprintf(buffer, "%*ld ", mpDir->GetBlockSizeLen(), (long)(Node.mSize / 1024)); Out << buffer;}template <class outputT>void WarDirfmtUnixLs<outputT>::OutLinks(outputT& Out, const WarDirListNode& Node){ char buffer[16]; sprintf(buffer, "%3u ", (unsigned)Node.mLinks); Out << buffer;}template <class outputT>void WarDirfmtUnixLs<outputT>::OutMode(outputT& Out, const WarDirListNode& Node){ char str[12]; switch(Node.mType) { case WarDirListNode::FT_DIR: str[0] = 'd'; break; case WarDirListNode::FT_LINK: str[0] = 'l'; break; default: str[0] = '-'; } str[1] = Node.mMode & S_IRUSR ? 'r' : '-'; str[2] = Node.mMode & S_IWUSR ? 'w' : '-'; str[3] = Node.mMode & S_IXUSR ? 'x' : '-'; str[4] = Node.mMode & S_IRGRP ? 'r' : '-'; str[5] = Node.mMode & S_IWGRP ? 'w' : '-'; str[6] = Node.mMode & S_IXGRP ? 'x' : '-'; str[7] = Node.mMode & S_IROTH ? 'r' : '-'; str[8] = Node.mMode & S_IWOTH ? 'w' : '-'; str[9] = Node.mMode & S_IXOTH ? 'x' : '-'; str[10] = ' '; // ACL str[11] = 0; Out << str;}template <class outputT>void WarDirfmtUnixLs<outputT>::OutDate(outputT& Out, const WarDirListNode& Node){ WarTime when, Now; war_ccstr_t fmt; switch (mTimeType) { case TIME_CTIME: when = Node.mCreationTime; break; case TIME_MTIME: when = Node.mModifyTime; break; case TIME_ATIME: when = Node.mAccessTime; break; } if (mDoFullTime) { fmt = "%a %b %d %H:%M:%S %Y "; } else { if (Now.GetTime() > when.GetTime() + 6L * 30L * 24L * 60L * 60L /* Old. */ || Now.GetTime() < when.GetTime() - 60L * 60L) /* In the future. */ { /* The file is fairly old or in the future. POSIX says the cutoff is 6 months old; approximate this by 6*30 days. Allow a 1 hour slop factor for what is considered "the future", to allow for NFS server/client clock disagreement. Show the year instead of the time of day. */ fmt = "%b %d %Y "; } else { fmt = "%b %d %H:%M "; } } Out << when.FormatGMT(fmt);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -