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 "ExpanderRules.h"
|
||||||
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <Path.h>
|
|
||||||
#include <NodeInfo.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
#include <NodeInfo.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
#include <compat/sys/stat.h>
|
#include <compat/sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - ExpanderRule
|
||||||
|
|
||||||
|
|
||||||
ExpanderRule::ExpanderRule(BString mimetype, BString filenameExtension,
|
ExpanderRule::ExpanderRule(BString mimetype, BString filenameExtension,
|
||||||
BString listingCmd, BString expandCmd)
|
BString listingCmd, BString expandCmd)
|
||||||
:
|
:
|
||||||
@@ -38,25 +42,39 @@ ExpanderRule::ExpanderRule(const char* mimetype, const char* filenameExtension,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - ExpanderRules
|
||||||
|
|
||||||
|
|
||||||
ExpanderRules::ExpanderRules()
|
ExpanderRules::ExpanderRules()
|
||||||
{
|
{
|
||||||
fList.AddItem(new ExpanderRule("", ".tar.gz", "tar -ztvf %s", "tar -zxf %s"));
|
fList.AddItem(new ExpanderRule("", ".tar.gz",
|
||||||
fList.AddItem(new ExpanderRule("", ".tar.bz2", "tar -jtvf %s", "tar -jxf %s"));
|
"tar -ztvf %s", "tar -zxf %s"));
|
||||||
fList.AddItem(new ExpanderRule("", ".tar.Z", "tar -Ztvf %s", "tar -Zxf %s"));
|
fList.AddItem(new ExpanderRule("", ".tar.bz2",
|
||||||
fList.AddItem(new ExpanderRule("", ".tgz", "tar -ztvf %s", "tar -zxf %s"));
|
"tar -jtvf %s", "tar -jxf %s"));
|
||||||
fList.AddItem(new ExpanderRule("application/x-tar", ".tar", "tar -tvf %s", "tar -xf %s"));
|
fList.AddItem(new ExpanderRule("", ".tar.Z",
|
||||||
fList.AddItem(new ExpanderRule("application/x-gzip", ".gz", "echo %s | sed 's/.gz$//g'", "gunzip -c %s > `echo %s | sed 's/.gz$//g'`"));
|
"tar -Ztvf %s", "tar -Zxf %s"));
|
||||||
fList.AddItem(new ExpanderRule("application/x-bzip2", ".bz2", "echo %s | sed 's/.bz2$//g'", "bunzip2 -k %s"));
|
fList.AddItem(new ExpanderRule("", ".tgz",
|
||||||
fList.AddItem(new ExpanderRule("application/zip", ".zip", "unzip -l %s", "unzip -o %s"));
|
"tar -ztvf %s", "tar -zxf %s"));
|
||||||
fList.AddItem(new ExpanderRule("application/x-zip-compressed", ".zip", "unzip -l %s", "unzip -o %s"));
|
fList.AddItem(new ExpanderRule("application/x-tar", ".tar",
|
||||||
fList.AddItem(new ExpanderRule("application/x-rar", ".rar", "unrar v %s", "unrar x -y %s"));
|
"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;
|
BFile file;
|
||||||
if (Open(&file) != B_OK)
|
if (_Open(&file) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int fd = file.Dup();
|
int fd = file.Dup();
|
||||||
FILE * f = fdopen(fd, "r");
|
FILE* f = fdopen(fd, "r");
|
||||||
|
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
BString strings[4];
|
BString strings[4];
|
||||||
@@ -66,14 +84,16 @@ ExpanderRules::ExpanderRules()
|
|||||||
while (buffer[i] != '#' && buffer[i] != '\n' && j < 4) {
|
while (buffer[i] != '#' && buffer[i] != '\n' && j < 4) {
|
||||||
if ((j == 0 || j > 1) && buffer[i] == '"') {
|
if ((j == 0 || j > 1) && buffer[i] == '"') {
|
||||||
if (firstQuote >= 0) {
|
if (firstQuote >= 0) {
|
||||||
strings[j++].SetTo(&buffer[firstQuote+1], i - firstQuote - 1);
|
strings[j++].SetTo(&buffer[firstQuote+1],
|
||||||
|
i - firstQuote - 1);
|
||||||
firstQuote = -1;
|
firstQuote = -1;
|
||||||
} else
|
} else
|
||||||
firstQuote = i;
|
firstQuote = i;
|
||||||
} else if (j == 1 && (buffer[i] == ' ' || buffer[i] == '\t')) {
|
} else if (j == 1 && (buffer[i] == ' ' || buffer[i] == '\t')) {
|
||||||
if (firstQuote >= 0) {
|
if (firstQuote >= 0) {
|
||||||
if (firstQuote + 1 != i) {
|
if (firstQuote + 1 != i) {
|
||||||
strings[j++].SetTo(&buffer[firstQuote+1], i - firstQuote - 1);
|
strings[j++].SetTo(&buffer[firstQuote+1],
|
||||||
|
i - firstQuote - 1);
|
||||||
firstQuote = -1;
|
firstQuote = -1;
|
||||||
} else
|
} else
|
||||||
firstQuote = i;
|
firstQuote = i;
|
||||||
@@ -83,7 +103,8 @@ ExpanderRules::ExpanderRules()
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (j == 4) {
|
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);
|
fclose(f);
|
||||||
@@ -93,14 +114,14 @@ ExpanderRules::ExpanderRules()
|
|||||||
|
|
||||||
ExpanderRules::~ExpanderRules()
|
ExpanderRules::~ExpanderRules()
|
||||||
{
|
{
|
||||||
void *item;
|
void* item;
|
||||||
while ((item = fList.RemoveItem((int32)0)))
|
while ((item = fList.RemoveItem((int32)0)))
|
||||||
delete (ExpanderRule*)item;
|
delete (ExpanderRule*)item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ExpanderRules::Open(BFile *file)
|
ExpanderRules::_Open(BFile* file)
|
||||||
{
|
{
|
||||||
directory_which which[] = {
|
directory_which which[] = {
|
||||||
B_USER_DATA_DIRECTORY,
|
B_USER_DATA_DIRECTORY,
|
||||||
@@ -121,13 +142,13 @@ ExpanderRules::Open(BFile *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ExpanderRule *
|
ExpanderRule*
|
||||||
ExpanderRules::MatchingRule(BString &fileName, const char *filetype)
|
ExpanderRules::MatchingRule(BString& fileName, const char* filetype)
|
||||||
{
|
{
|
||||||
int32 count = fList.CountItems();
|
int32 count = fList.CountItems();
|
||||||
int32 length = fileName.Length();
|
int32 length = fileName.Length();
|
||||||
for (int32 i = 0; i < count; i++) {
|
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)
|
if (rule->MimeType().IsValid() && rule->MimeType() == filetype)
|
||||||
return rule;
|
return rule;
|
||||||
int32 extPosition = fileName.FindLast(rule->FilenameExtension());
|
int32 extPosition = fileName.FindLast(rule->FilenameExtension());
|
||||||
@@ -139,8 +160,8 @@ ExpanderRules::MatchingRule(BString &fileName, const char *filetype)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ExpanderRule *
|
ExpanderRule*
|
||||||
ExpanderRules::MatchingRule(const entry_ref *ref)
|
ExpanderRules::MatchingRule(const entry_ref* ref)
|
||||||
{
|
{
|
||||||
BEntry entry(ref, true);
|
BEntry entry(ref, true);
|
||||||
BNode node(&entry);
|
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(),
|
: BRefFilter(),
|
||||||
fRules(rules)
|
fRules(rules)
|
||||||
{
|
{
|
||||||
@@ -160,8 +184,8 @@ RuleRefFilter::RuleRefFilter(ExpanderRules &rules)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
RuleRefFilter::Filter(const entry_ref *ref, BNode* node, struct stat_beos *st,
|
RuleRefFilter::Filter(const entry_ref* ref, BNode* node, struct stat_beos* st,
|
||||||
const char *filetype)
|
const char* filetype)
|
||||||
{
|
{
|
||||||
if (node->IsDirectory() || node->IsSymLink())
|
if (node->IsDirectory() || node->IsSymLink())
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -3,53 +3,69 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef _ExpanderRules_h
|
#ifndef _ExpanderRules_h
|
||||||
#define _ExpanderRules_h
|
#define _ExpanderRules_h
|
||||||
|
|
||||||
#include <List.h>
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <String.h>
|
|
||||||
#include <Mime.h>
|
|
||||||
#include <FilePanel.h>
|
#include <FilePanel.h>
|
||||||
|
#include <List.h>
|
||||||
|
#include <Mime.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
class ExpanderRule {
|
class ExpanderRule {
|
||||||
public:
|
public:
|
||||||
ExpanderRule(BString mimetype, BString filenameExtension,
|
ExpanderRule(BString mimetype,
|
||||||
BString listingCmd, BString expandCmd);
|
BString filenameExtension,
|
||||||
ExpanderRule(const char* mimetype, const char* filenameExtension,
|
BString listingCmd, BString expandCmd);
|
||||||
const char* listingCmd, const char* expandCmd);
|
ExpanderRule(const char* mimetype,
|
||||||
BMimeType &MimeType() { return fMimeType;}
|
const char* filenameExtension,
|
||||||
BString &FilenameExtension() { return fFilenameExtension;}
|
const char* listingCmd,
|
||||||
BString &ListingCmd() { return fListingCmd;}
|
const char* expandCmd);
|
||||||
BString &ExpandCmd() { return fExpandCmd;}
|
|
||||||
private:
|
const BMimeType& MimeType() const
|
||||||
BMimeType fMimeType;
|
{ return fMimeType; }
|
||||||
BString fFilenameExtension;
|
const BString& FilenameExtension() const
|
||||||
BString fListingCmd;
|
{ return fFilenameExtension; }
|
||||||
BString fExpandCmd;
|
const BString& ListingCmd() const
|
||||||
|
{ return fListingCmd; }
|
||||||
|
const BString& ExpandCmd() const
|
||||||
|
{ return fExpandCmd; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
BMimeType fMimeType;
|
||||||
|
BString fFilenameExtension;
|
||||||
|
BString fListingCmd;
|
||||||
|
BString fExpandCmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ExpanderRules {
|
class ExpanderRules {
|
||||||
public:
|
public:
|
||||||
ExpanderRules();
|
ExpanderRules();
|
||||||
~ExpanderRules();
|
~ExpanderRules();
|
||||||
ExpanderRule *MatchingRule(BString &fileName, const char *filetype);
|
|
||||||
ExpanderRule *MatchingRule(const entry_ref *ref);
|
|
||||||
private:
|
|
||||||
status_t Open(BFile *file);
|
|
||||||
|
|
||||||
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 {
|
class RuleRefFilter : public BRefFilter {
|
||||||
public:
|
public:
|
||||||
RuleRefFilter(ExpanderRules &rules);
|
RuleRefFilter(ExpanderRules& rules);
|
||||||
bool Filter(const entry_ref *ref, BNode* node, struct stat_beos *st,
|
bool Filter(const entry_ref* ref, BNode* node,
|
||||||
const char *filetype);
|
struct stat_beos* st, const char* filetype);
|
||||||
protected:
|
protected:
|
||||||
ExpanderRules &fRules;
|
ExpanderRules& fRules;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* _ExpanderRules_h */
|
#endif /* _ExpanderRules_h */
|
||||||
|
|||||||
Reference in New Issue
Block a user