ExpanderRules: Coding style update
Also makes the ExpanderRule getters const. No other functional change.
This commit is contained in:
@@ -6,16 +6,20 @@
|
||||
|
||||
#include "ExpanderRules.h"
|
||||
|
||||
#include <FindDirectory.h>
|
||||
#include <stdlib.h>
|
||||
#include <Path.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <FindDirectory.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Path.h>
|
||||
|
||||
#include <compat/sys/stat.h>
|
||||
|
||||
|
||||
// #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;
|
||||
|
||||
@@ -3,53 +3,69 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _ExpanderRules_h
|
||||
#define _ExpanderRules_h
|
||||
|
||||
#include <List.h>
|
||||
#include <File.h>
|
||||
#include <String.h>
|
||||
#include <Mime.h>
|
||||
#include <FilePanel.h>
|
||||
#include <List.h>
|
||||
#include <Mime.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
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 */
|
||||
|
||||
Reference in New Issue
Block a user