From 2cf916cbe2e43b8e562b87f43ba8b69584d5c785 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 29 Jun 2013 18:28:06 +0200 Subject: [PATCH] ExpanderRules: Coding style update Also makes the ExpanderRule getters const. No other functional change. --- src/apps/expander/ExpanderRules.cpp | 80 +++++++++++++++++++---------- src/apps/expander/ExpanderRules.h | 78 +++++++++++++++++----------- 2 files changed, 99 insertions(+), 59 deletions(-) diff --git a/src/apps/expander/ExpanderRules.cpp b/src/apps/expander/ExpanderRules.cpp index 55452f0296..9a42eae2f6 100644 --- a/src/apps/expander/ExpanderRules.cpp +++ b/src/apps/expander/ExpanderRules.cpp @@ -6,16 +6,20 @@ #include "ExpanderRules.h" -#include #include -#include -#include #include #include +#include +#include +#include + #include +// #pragma mark - ExpanderRule + + ExpanderRule::ExpanderRule(BString mimetype, BString filenameExtension, BString listingCmd, BString expandCmd) : @@ -38,25 +42,39 @@ ExpanderRule::ExpanderRule(const char* mimetype, const char* filenameExtension, } +// #pragma mark - ExpanderRules + + ExpanderRules::ExpanderRules() { - fList.AddItem(new ExpanderRule("", ".tar.gz", "tar -ztvf %s", "tar -zxf %s")); - fList.AddItem(new ExpanderRule("", ".tar.bz2", "tar -jtvf %s", "tar -jxf %s")); - fList.AddItem(new ExpanderRule("", ".tar.Z", "tar -Ztvf %s", "tar -Zxf %s")); - fList.AddItem(new ExpanderRule("", ".tgz", "tar -ztvf %s", "tar -zxf %s")); - fList.AddItem(new ExpanderRule("application/x-tar", ".tar", "tar -tvf %s", "tar -xf %s")); - fList.AddItem(new ExpanderRule("application/x-gzip", ".gz", "echo %s | sed 's/.gz$//g'", "gunzip -c %s > `echo %s | sed 's/.gz$//g'`")); - fList.AddItem(new ExpanderRule("application/x-bzip2", ".bz2", "echo %s | sed 's/.bz2$//g'", "bunzip2 -k %s")); - fList.AddItem(new ExpanderRule("application/zip", ".zip", "unzip -l %s", "unzip -o %s")); - fList.AddItem(new ExpanderRule("application/x-zip-compressed", ".zip", "unzip -l %s", "unzip -o %s")); - fList.AddItem(new ExpanderRule("application/x-rar", ".rar", "unrar v %s", "unrar x -y %s")); + fList.AddItem(new ExpanderRule("", ".tar.gz", + "tar -ztvf %s", "tar -zxf %s")); + fList.AddItem(new ExpanderRule("", ".tar.bz2", + "tar -jtvf %s", "tar -jxf %s")); + fList.AddItem(new ExpanderRule("", ".tar.Z", + "tar -Ztvf %s", "tar -Zxf %s")); + fList.AddItem(new ExpanderRule("", ".tgz", + "tar -ztvf %s", "tar -zxf %s")); + fList.AddItem(new ExpanderRule("application/x-tar", ".tar", + "tar -tvf %s", "tar -xf %s")); + fList.AddItem(new ExpanderRule("application/x-gzip", ".gz", + "echo %s | sed 's/.gz$//g'", + "gunzip -c %s > `echo %s | sed 's/.gz$//g'`")); + fList.AddItem(new ExpanderRule("application/x-bzip2", ".bz2", + "echo %s | sed 's/.bz2$//g'", "bunzip2 -k %s")); + fList.AddItem(new ExpanderRule("application/zip", ".zip", + "unzip -l %s", "unzip -o %s")); + fList.AddItem(new ExpanderRule("application/x-zip-compressed", ".zip", + "unzip -l %s", "unzip -o %s")); + fList.AddItem(new ExpanderRule("application/x-rar", ".rar", + "unrar v %s", "unrar x -y %s")); BFile file; - if (Open(&file) != B_OK) + if (_Open(&file) != B_OK) return; int fd = file.Dup(); - FILE * f = fdopen(fd, "r"); + FILE* f = fdopen(fd, "r"); char buffer[1024]; BString strings[4]; @@ -66,14 +84,16 @@ ExpanderRules::ExpanderRules() while (buffer[i] != '#' && buffer[i] != '\n' && j < 4) { if ((j == 0 || j > 1) && buffer[i] == '"') { if (firstQuote >= 0) { - strings[j++].SetTo(&buffer[firstQuote+1], i - firstQuote - 1); + strings[j++].SetTo(&buffer[firstQuote+1], + i - firstQuote - 1); firstQuote = -1; } else firstQuote = i; } else if (j == 1 && (buffer[i] == ' ' || buffer[i] == '\t')) { if (firstQuote >= 0) { if (firstQuote + 1 != i) { - strings[j++].SetTo(&buffer[firstQuote+1], i - firstQuote - 1); + strings[j++].SetTo(&buffer[firstQuote+1], + i - firstQuote - 1); firstQuote = -1; } else firstQuote = i; @@ -83,7 +103,8 @@ ExpanderRules::ExpanderRules() i++; } if (j == 4) { - fList.AddItem(new ExpanderRule(strings[0], strings[1], strings[2], strings[3])); + fList.AddItem(new ExpanderRule(strings[0], strings[1], strings[2], + strings[3])); } } fclose(f); @@ -93,14 +114,14 @@ ExpanderRules::ExpanderRules() ExpanderRules::~ExpanderRules() { - void *item; + void* item; while ((item = fList.RemoveItem((int32)0))) delete (ExpanderRule*)item; } status_t -ExpanderRules::Open(BFile *file) +ExpanderRules::_Open(BFile* file) { directory_which which[] = { B_USER_DATA_DIRECTORY, @@ -121,13 +142,13 @@ ExpanderRules::Open(BFile *file) } -ExpanderRule * -ExpanderRules::MatchingRule(BString &fileName, const char *filetype) +ExpanderRule* +ExpanderRules::MatchingRule(BString& fileName, const char* filetype) { int32 count = fList.CountItems(); int32 length = fileName.Length(); for (int32 i = 0; i < count; i++) { - ExpanderRule *rule = (ExpanderRule *)fList.ItemAt(i); + ExpanderRule* rule = (ExpanderRule*)fList.ItemAt(i); if (rule->MimeType().IsValid() && rule->MimeType() == filetype) return rule; int32 extPosition = fileName.FindLast(rule->FilenameExtension()); @@ -139,8 +160,8 @@ ExpanderRules::MatchingRule(BString &fileName, const char *filetype) } -ExpanderRule * -ExpanderRules::MatchingRule(const entry_ref *ref) +ExpanderRule* +ExpanderRules::MatchingRule(const entry_ref* ref) { BEntry entry(ref, true); BNode node(&entry); @@ -152,7 +173,10 @@ ExpanderRules::MatchingRule(const entry_ref *ref) } -RuleRefFilter::RuleRefFilter(ExpanderRules &rules) +// #pragma mark - RuleRefFilter + + +RuleRefFilter::RuleRefFilter(ExpanderRules& rules) : BRefFilter(), fRules(rules) { @@ -160,8 +184,8 @@ RuleRefFilter::RuleRefFilter(ExpanderRules &rules) bool -RuleRefFilter::Filter(const entry_ref *ref, BNode* node, struct stat_beos *st, - const char *filetype) +RuleRefFilter::Filter(const entry_ref* ref, BNode* node, struct stat_beos* st, + const char* filetype) { if (node->IsDirectory() || node->IsSymLink()) return true; diff --git a/src/apps/expander/ExpanderRules.h b/src/apps/expander/ExpanderRules.h index 14cfbe703a..8918f9292e 100644 --- a/src/apps/expander/ExpanderRules.h +++ b/src/apps/expander/ExpanderRules.h @@ -3,53 +3,69 @@ * Distributed under the terms of the MIT License. */ + #ifndef _ExpanderRules_h #define _ExpanderRules_h -#include #include -#include -#include #include +#include +#include +#include + class ExpanderRule { - public: - ExpanderRule(BString mimetype, BString filenameExtension, - BString listingCmd, BString expandCmd); - ExpanderRule(const char* mimetype, const char* filenameExtension, - const char* listingCmd, const char* expandCmd); - BMimeType &MimeType() { return fMimeType;} - BString &FilenameExtension() { return fFilenameExtension;} - BString &ListingCmd() { return fListingCmd;} - BString &ExpandCmd() { return fExpandCmd;} - private: - BMimeType fMimeType; - BString fFilenameExtension; - BString fListingCmd; - BString fExpandCmd; +public: + ExpanderRule(BString mimetype, + BString filenameExtension, + BString listingCmd, BString expandCmd); + ExpanderRule(const char* mimetype, + const char* filenameExtension, + const char* listingCmd, + const char* expandCmd); + + const BMimeType& MimeType() const + { return fMimeType; } + const BString& FilenameExtension() const + { return fFilenameExtension; } + const BString& ListingCmd() const + { return fListingCmd; } + const BString& ExpandCmd() const + { return fExpandCmd; } + +private: + BMimeType fMimeType; + BString fFilenameExtension; + BString fListingCmd; + BString fExpandCmd; }; class ExpanderRules { - public: - ExpanderRules(); - ~ExpanderRules(); - ExpanderRule *MatchingRule(BString &fileName, const char *filetype); - ExpanderRule *MatchingRule(const entry_ref *ref); - private: - status_t Open(BFile *file); +public: + ExpanderRules(); + ~ExpanderRules(); - BList fList; + ExpanderRule* MatchingRule(BString& fileName, + const char* filetype); + ExpanderRule* MatchingRule(const entry_ref* ref); + +private: + status_t _Open(BFile* file); + +private: + BList fList; }; class RuleRefFilter : public BRefFilter { - public: - RuleRefFilter(ExpanderRules &rules); - bool Filter(const entry_ref *ref, BNode* node, struct stat_beos *st, - const char *filetype); - protected: - ExpanderRules &fRules; +public: + RuleRefFilter(ExpanderRules& rules); + bool Filter(const entry_ref* ref, BNode* node, + struct stat_beos* st, const char* filetype); +protected: + ExpanderRules& fRules; }; + #endif /* _ExpanderRules_h */