void TOpts::PrintFreeArgsDesc(IOutputStream& os, const NColorizer::TColors& colors) const { if (0 == FreeArgsMax_) return; size_t leftFreeWidth = 0; for (size_t i = 0; i < FreeArgSpecs_.size(); ++i) { leftFreeWidth = Max(leftFreeWidth, GetFreeArgTitle(i).size()); } if (CustomDefaultArg_) { leftFreeWidth = Max(leftFreeWidth, DefaultFreeArgSpec.Title.size()); } leftFreeWidth = Min(leftFreeWidth, size_t(30)); os << Endl << colors.BoldColor() << "Free args"<< colors.OldColor() <<":"; os << " min: " << colors.GreenColor() << FreeArgsMin_ << colors.OldColor() << ","; os << " max: " << colors.GreenColor(); if (FreeArgsMax_ != Max<ui32>()) { os << FreeArgsMax_; } else { os << "unlimited"; } os << colors.OldColor(); os << " (listed described args only)" << Endl; const size_t limit = FreeArgSpecs_.empty() ? 0 : FreeArgSpecs_.rbegin()->first; for (size_t i = 0; i <= limit; ++i) { const TString& help = GetFreeArgHelp(i); os << " " << colors.GreenColor() << RightPad(GetFreeArgTitle(i), leftFreeWidth, ' ') << colors.OldColor(); if (!help.Empty()) os << " " << help; os << Endl; } if (CustomDefaultArg_) { os << " " << colors.GreenColor() << RightPad(DefaultFreeArgSpec.Title, leftFreeWidth, ' ') << colors.OldColor(); os << " " << (!DefaultFreeArgSpec.Help ? DefaultHelp : DefaultFreeArgSpec.Help); os << Endl; } }
void TOpts::PrintFreeArgsDesc(TOutputStream& os) const { if (0 == FreeArgsMax_) return; size_t leftFreeWidth = 0; for (size_t i = 0; i < FreeArgSpecs_.size(); ++i) { leftFreeWidth = Max(leftFreeWidth, GetFreeArgTitle(i).size()); } if (CustomDefaultArg_) { leftFreeWidth = Max(leftFreeWidth, DefaultArgTitle_.size()); } leftFreeWidth = Min(leftFreeWidth, size_t(30)); os << Endl << "Free args:"; os << " min: " << FreeArgsMin_ << ","; os << " max: "; if (FreeArgsMax_ != Max<ui32>()) { os << FreeArgsMax_; } else { os << "unlimited"; } os << " (listed described args only)" << Endl; for (size_t i = 0; i < FreeArgSpecs_.size(); ++i) { const Stroka& help = GetFreeArgHelp(i); os << " " << RightPad(GetFreeArgTitle(i), leftFreeWidth, ' '); if (!help.Empty()) os << " " << help; os << Endl; } if (CustomDefaultArg_) { os << " " << RightPad(DefaultArgTitle_, leftFreeWidth, ' '); if (!DefaultArgHelp_.Empty()) os << " " << (!DefaultArgHelp_ ? DefaultHelp : DefaultArgHelp_); os << Endl; } }
/**************************************************** inputs needed : Handle of the file containing all the addresses returns nothing Prints Count of Unique addresses **************************************************/ PrintIpCount(FILE *ip_read) { int len; char iptemp[30], ip_check[30]; int k, j,ipCount=0, maxc=0,ipMaxCount=0; for(k=0;k< count ; k++) { fgets(iptemp , 20,ip_read); len = strlen(iptemp); if(iptemp[len-1]=='\n') iptemp[len-1]='\0'; strcpy(ip_list[k].ip, iptemp); maxc++; if(feof(ip_read)) break; } int tempCount; int iCopyTemp=0; char *p; for(k=0;k<maxc;k++) //outer loop { if(strcmp(ip_list[k].ip,"done") != 0) { strcpy(ip_check , ip_list[k].ip); for(j= 0, tempCount=0; j<maxc; j++,tempCount++) //inner loop { if(strcmp(ip_check, ip_list[tempCount].ip) == 0 ) { iCopyTemp++; strcpy(ip_list[tempCount].ip,"done"); } }//End of j loop strcpy(ip_count[ipCount].ip, ip_check); // ip_count is a unique ip recorder structure ip_count[ipCount].count=iCopyTemp; ipCount++; ipMaxCount++; iCopyTemp = 0; } } //End of k loop for(k=0;k< ipMaxCount ; k++) { printf(" %s\t\t %d\n",RightPad( ip_count[k].ip, 20," "), ip_count[k].count); } }
void TOpts::PrintUsage(const TStringBuf& program, TOutputStream& os) const { if (!Title.empty()) os << Title << "\n\n"; PrintCmdLine(program, os); yvector<Stroka> leftColumn(Opts_.size()); size_t leftWidth = 0; size_t requiredOptionsCount = 0; for (size_t i = 0; i < Opts_.size(); i++) { const TOpt* opt = Opts_[i].Get(); if (opt->IsHidden()) continue; leftColumn[i] = FormatOption(opt); leftWidth = Max(leftWidth, leftColumn[i].size()); if (opt->IsRequired()) requiredOptionsCount++; } const size_t kMaxLeftWidth = 25; leftWidth = Min(leftWidth, kMaxLeftWidth); const Stroka maxPadding(kMaxLeftWidth, ' '); const Stroka leftPadding(leftWidth, ' '); for (size_t sectionId = 0; sectionId <= 1; sectionId++) { bool requiredOptionsSection = (sectionId == 0); if (requiredOptionsSection) { if (requiredOptionsCount == 0) continue; os << Endl << "Required parameters:" << Endl; } else { if (requiredOptionsCount == Opts_.size()) continue; if (requiredOptionsCount == 0) os << Endl << "Options:" << Endl; else os << Endl << "Optional parameters:" << Endl; // optional options would be a tautology } for (size_t i = 0; i < Opts_.size(); i++) { const TOpt* opt = Opts_[i].Get(); if (opt->IsHidden()) continue; if (opt->IsRequired() != requiredOptionsSection) continue; if (leftColumn[i].size() > leftWidth && !opt->Help_.empty()) os << SPad << leftColumn[i] << Endl << SPad << maxPadding << ' '; else os << SPad << RightPad(leftColumn[i], leftWidth, ' ') << ' '; bool multiLineHelp = false; if (!opt->Help_.empty()) { yvector<TStringBuf> helpLines; Split(opt->Help_, "\n", helpLines); multiLineHelp = (helpLines.size() > 1); os << helpLines[0]; for (size_t j = 1; j < helpLines.size(); ++j) { if (helpLines[j].empty()) continue; os << Endl << SPad << leftPadding << ' ' << helpLines[j]; } } if (opt->HasDefaultValue()) { Stroka quotedDef = QuoteForHelp(opt->GetDefaultValue()); if (multiLineHelp) os << Endl << SPad << leftPadding << " Default: " << quotedDef; else if (opt->Help_.empty()) os << "Default: " << quotedDef; else os << " (default: " << quotedDef << ")"; } os << Endl; } } PrintFreeArgsDesc(os); }