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,21 +42,35 @@ 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();
|
||||
@@ -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);
|
||||
@@ -100,7 +121,7 @@ ExpanderRules::~ExpanderRules()
|
||||
|
||||
|
||||
status_t
|
||||
ExpanderRules::Open(BFile *file)
|
||||
ExpanderRules::_Open(BFile* file)
|
||||
{
|
||||
directory_which which[] = {
|
||||
B_USER_DATA_DIRECTORY,
|
||||
@@ -152,6 +173,9 @@ ExpanderRules::MatchingRule(const entry_ref *ref)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - RuleRefFilter
|
||||
|
||||
|
||||
RuleRefFilter::RuleRefFilter(ExpanderRules& rules)
|
||||
: BRefFilter(),
|
||||
fRules(rules)
|
||||
|
||||
@@ -3,25 +3,36 @@
|
||||
* 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,
|
||||
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;}
|
||||
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;
|
||||
@@ -34,11 +45,15 @@ class ExpanderRules {
|
||||
public:
|
||||
ExpanderRules();
|
||||
~ExpanderRules();
|
||||
ExpanderRule *MatchingRule(BString &fileName, const char *filetype);
|
||||
ExpanderRule *MatchingRule(const entry_ref *ref);
|
||||
private:
|
||||
status_t Open(BFile *file);
|
||||
|
||||
ExpanderRule* MatchingRule(BString& fileName,
|
||||
const char* filetype);
|
||||
ExpanderRule* MatchingRule(const entry_ref* ref);
|
||||
|
||||
private:
|
||||
status_t _Open(BFile* file);
|
||||
|
||||
private:
|
||||
BList fList;
|
||||
};
|
||||
|
||||
@@ -46,10 +61,11 @@ class ExpanderRules {
|
||||
class RuleRefFilter : public BRefFilter {
|
||||
public:
|
||||
RuleRefFilter(ExpanderRules& rules);
|
||||
bool Filter(const entry_ref *ref, BNode* node, struct stat_beos *st,
|
||||
const char *filetype);
|
||||
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