Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anbr committed Dec 21, 2010
1 parent 2906f2d commit 3837f9a
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 99 deletions.
3 changes: 3 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
VDR Plugin 'dvdswitch' Revision History
---------------------------------------

2009-10-03: Version 0.1.5
- Fix some GCC-4.4 warnings

2009-10-03: Version 0.1.4
- Update to vdr 1.6.0

Expand Down
7 changes: 4 additions & 3 deletions dvdlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ bool cDVDList::Load(const char *dir, eFileList smode, bool sub)
char *extexp = NULL;
for(i = 1; i <= token->Count(); i++)
{
asprintf(&extexp, "%s$", token->GetToken(i));
fList->OptInclude(extexp, tFile);
FREENULL(extexp);
if(0 < asprintf(&extexp, "%s$", token->GetToken(i))) {
fList->OptInclude(extexp, tFile);
FREENULL(extexp);
}
}
delete(token);
}
Expand Down
125 changes: 64 additions & 61 deletions dvdplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,79 +67,81 @@ void cDVDPlugin::DetectDevice(void)
char *output = NULL;
char *dvd = NULL;

asprintf(&cmd, "ps -p %i -o cmd --no-header", getpid());
dsyslog("Commando: %s", cmd);
if(0 < asprintf(&cmd, "ps -p %i -o cmd --no-header", getpid())) {
dsyslog("Commando: %s", cmd);

FILE *p = popen(cmd, "r");
if(p)
{
#if VDRVERSNUM >= 10318
cReadLine rl;
output = rl.Read(p);
#else
output = readline(p);
#endif
pclose(p);
}
FILE *p = popen(cmd, "r");
if(p)
{
#if VDRVERSNUM >= 10318
cReadLine rl;
output = rl.Read(p);
#else
output = readline(p);
#endif
pclose(p);
}

cTokenizer *token = new cTokenizer(output, " ");
for(int i = 1; i <= token->Count(); i++)
{
if(RegIMatch(token->GetToken(i), "^--plugin=dvd") ||
(RegIMatch(token->GetToken(i - 1), "^-P$") &&
RegIMatch(token->GetToken(i), "^dvd$")))
cTokenizer *token = new cTokenizer(output, " ");
for(int i = 1; i <= token->Count(); i++)
{
if(RegIMatch(token->GetToken(i + 1), "^-C$") &&
token->GetToken(i + 2))
if(RegIMatch(token->GetToken(i), "^--plugin=dvd") ||
(RegIMatch(token->GetToken(i - 1), "^-P$") &&
RegIMatch(token->GetToken(i), "^dvd$")))
{
dvd = strdup(token->GetToken(i + 2));
break;
}
if(RegIMatch(token->GetToken(i + 1), "^--dvd="))
{
char *p = strchr(token->GetToken(i + 1), '=');
p++;
dvd = strdup(p);
break;
if(RegIMatch(token->GetToken(i + 1), "^-C$") &&
token->GetToken(i + 2))
{
dvd = strdup(token->GetToken(i + 2));
break;
}
if(RegIMatch(token->GetToken(i + 1), "^--dvd="))
{
const char *p = strchr(token->GetToken(i + 1), '=');
p++;
dvd = strdup(p);
break;
}
}
}
DELETENULL(token);

if(dvd)
{
isyslog("Used DVD Device: %s", dvd);
DVDSwitchSetup.SetDVDDevice(dvd);
free(dvd);
}
else
{
isyslog("Use Default-DVD Device /dev/dvd");
DVDSwitchSetup.SetDVDDevice("/dev/dvd");
}

free(cmd);
}
DELETENULL(token);

if(dvd)
{
isyslog("Used DVD Device: %s", dvd);
DVDSwitchSetup.SetDVDDevice(dvd);
}
else
{
isyslog("Use Default-DVD Device /dev/dvd");
DVDSwitchSetup.SetDVDDevice("/dev/dvd");
}

free(cmd);
free(dvd);
//free(output);
}

void cDVDPlugin::SetLink(void)
{
int argc = 2;
char *argv[2] = { NULL, NULL };

asprintf(&argv[0], "%s", "dvd");
asprintf(&argv[1], "--dvd=%s", DVDSwitchSetup.DVDLink);
if(0 < asprintf(&argv[0], "%s", "dvd")) {
if(0 < asprintf(&argv[1], "--dvd=%s", DVDSwitchSetup.DVDLink)) {

cPlugin *plugin = cPluginManager::GetPlugin("dvd");
cPlugin *plugin = cPluginManager::GetPlugin("dvd");

if(plugin)
{
optind = 0; //reset for getopt
plugin->ProcessArgs(argc, argv);
}
if(plugin)
{
optind = 0; //reset for getopt
plugin->ProcessArgs(argc, argv);
}

free(argv[0]);
free(argv[1]);
free(argv[1]);
}
free(argv[0]);
}
}

void cDVDPlugin::Start(char *image)
Expand All @@ -164,10 +166,11 @@ void cDVDPlugin::ChangeLink(char *target)
char *cmd = NULL;
int rc = 0;

asprintf(&cmd, LINK, target, DVDSwitchSetup.DVDLink);
dsyslog("Change link: %s", cmd);
rc = system(cmd);
dsyslog("Change link got: %i", rc);
free(cmd);
if(0 < asprintf(&cmd, LINK, target, DVDSwitchSetup.DVDLink)) {
dsyslog("Change link: %s", cmd);
rc = system(cmd);
dsyslog("Change link got: %i", rc);
free(cmd);
}
}
}
2 changes: 1 addition & 1 deletion dvdswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#error "VDR-1.6.0 API version or greater is required!"
#endif

static const char *VERSION = "0.1.4";
static const char *VERSION = "0.1.5";
static const char *DESCRIPTION = tr("Allowed to play DVD-Images");
//static const char *MAINMENUENTRY = tr("DVDSwitch");

Expand Down
44 changes: 25 additions & 19 deletions helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,14 @@ cFileListItem::cFileListItem(const char *dir, const char *file)
{
if(file && !isempty(file) && dir && !isempty(dir))
{
if(dir[strlen(dir) - 1] == '/')
asprintf(&File, "%s%s", dir, file);
else
asprintf(&File, "%s/%s", dir, file);
if(dir[strlen(dir) - 1] == '/') {
if(0 >= asprintf(&File, "%s%s", dir, file))
return;
}
else {
if(0 >= asprintf(&File, "%s/%s", dir, file))
return;
}
}
else
File = NULL;
Expand Down Expand Up @@ -514,9 +518,10 @@ bool cFileList::Read(const char *dir, bool withsub)
CheckType(dir, DirData->d_name, tDir) &&
!RegIMatch(DirData->d_name, "^\\.{1,2}$"))
{
asprintf(&buffer, "%s/%s", dir, DirData->d_name);
Read(buffer, withsub);
FREENULL(buffer);
if(0 < asprintf(&buffer, "%s/%s", dir, DirData->d_name)) {
Read(buffer, withsub);
FREENULL(buffer);
}
}
}
ret = true;
Expand All @@ -541,7 +546,8 @@ void cFileList::SortIn(const char *dir, const char *file)
case sDesc:
if(Item)
{
asprintf(&NewItem, "%s/%s", dir, file);
if(0 >= asprintf(&NewItem, "%s/%s", dir, file))
break;
NewItemInfo = SortToFilename ? new cFileInfo(NewItem) : NULL;
while(Item)
{
Expand Down Expand Up @@ -618,15 +624,14 @@ bool cFileList::CheckType(const char *dir, const char *file, eFileInfo type)

char *buffer = NULL;

asprintf(&buffer, "%s/%s", dir, file);

cFileInfo *info = new cFileInfo(buffer);
if(info->Type() == type)
ret = true;
delete(info);

free(buffer);
if(0 < asprintf(&buffer, "%s/%s", dir, file)) {
cFileInfo *info = new cFileInfo(buffer);
if(info->Type() == type)
ret = true;
delete(info);

free(buffer);
}
return ret;
}

Expand Down Expand Up @@ -670,9 +675,10 @@ bool cFileList::DirIsIn(const char *file, const char *strings)
cTokenizer *token = new cTokenizer(strings, "@");
for(int i = 1; i <= token->Count(); i++)
{
asprintf(&buffer, "^%s$", token->GetToken(i));
fList->OptInclude(buffer);
free(buffer);
if(0 < asprintf(&buffer, "^%s$", token->GetToken(i))) {
fList->OptInclude(buffer);
free(buffer);
}
}
DELETENULL(token);

Expand Down
7 changes: 5 additions & 2 deletions imagelist-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ void cImageListItem::Edit(const char *lname, const char *sname, eFileInfo type,
LName = lname ? strdup(lname) : NULL;
SName = sname ? strdup(sname) : NULL;

if(type == tFile && value && value[0] != '.')
asprintf(&Value, ".%s", value);
if(type == tFile && value && value[0] != '.') {
if(0 >= asprintf(&Value, ".%s", value)) {
return;
}
}
else
Value = value ? strdup(value) : NULL;

Expand Down
6 changes: 3 additions & 3 deletions imagelist-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class cImageListItem : public cListObject

void MakeSetupString(void)
{
dsyslog("Neuer SetupString");
FREENULL(SString);
asprintf(&SString, "%s|%s|%i|%s|%i", LName, SName, (int)fType, Value, HideExt);
dsyslog("...%s", SString);
if(0 < asprintf(&SString, "%s|%s|%i|%s|%i", LName, SName, (int)fType, Value, HideExt)) {
dsyslog("...%s", SString);
}
};

void debug(void);
Expand Down
7 changes: 4 additions & 3 deletions tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ cDirList::cDirList(cImageList &ImageList)
cTokenizer *token = new cTokenizer(ImageList.GetDirContains(), "@");
for(int i = 1; i <= token->Count(); i++)
{
asprintf(&buffer, "^%s$", token->GetToken(i));
OptExclude(buffer);
FREENULL(buffer);
if(0 < asprintf(&buffer, "^%s$", token->GetToken(i))) {
OptExclude(buffer);
FREENULL(buffer);
}
}

OptSort((eFileList)DVDSwitchSetup.SortMode);
Expand Down
17 changes: 10 additions & 7 deletions tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ class cFileDelThread : public cThread
Ok = true;
if(file)
{
asprintf(&File, "%s.sdel", file);
cFileCMD::Rn(file, File);
if(0 < asprintf(&File, "%s.sdel", file)) {
cFileCMD::Rn(file, File);
}
}
}
}
Expand Down Expand Up @@ -80,9 +81,10 @@ class cFileMoveThread : public cThread
if(FileName && File && Dest)
{
char *buffer = NULL;
asprintf(&buffer, "%s/%s", Dest, FileName);
cFileCMD::Rn(File, buffer);
free(buffer);
if(0 < asprintf(&buffer, "%s/%s", Dest, FileName)) {
cFileCMD::Rn(File, buffer);
free(buffer);
}
}
delete(this);
};
Expand All @@ -104,8 +106,9 @@ class cFileMoveThread : public cThread
cFileInfo *info = new cFileInfo(file);
FileName = strdup(info->FileName());
DELETENULL(info);
asprintf(&File, "%s.smove", file);
cFileCMD::Rn(file, File);
if(0 < asprintf(&File, "%s.smove", file)) {
cFileCMD::Rn(file, File);
}
}
Dest = dest ? strdup(dest) : NULL;
}
Expand Down

0 comments on commit 3837f9a

Please sign in to comment.