1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Now using qsort() to sort cListBase lists

This commit is contained in:
Klaus Schmidinger 2004-11-01 10:40:38 +01:00
parent c88e65b638
commit 0b62aff0e3
13 changed files with 96 additions and 75 deletions

View File

@ -3078,7 +3078,7 @@ Video Disk Recorder Revision History
This avoids shortly seeing the wrong events in the channel display when This avoids shortly seeing the wrong events in the channel display when
switching to a channel that hasn't been tuned to in a while. switching to a channel that hasn't been tuned to in a while.
2004-10-31: Version 1.3.15 2004-11-01: Version 1.3.15
- Fixed some typos in the Makefile's 'font' target (thanks to Uwe Hanke). - Fixed some typos in the Makefile's 'font' target (thanks to Uwe Hanke).
- Added more checks and polling when getting frontend events (based on a patch - Added more checks and polling when getting frontend events (based on a patch
@ -3105,3 +3105,7 @@ Video Disk Recorder Revision History
swapped (see man vdr(5)). swapped (see man vdr(5)).
- Added the 'portal name' to cChannels (thanks to Marco Schlüßler). - Added the 'portal name' to cChannels (thanks to Marco Schlüßler).
- Fixed handling key codes that start with 0x1B in the KBD remote control code. - Fixed handling key codes that start with 0x1B in the KBD remote control code.
- Now using qsort() to sort cListBase lists. For this, the virtual function
cListObject::operator<() has been replaced with cListObject::Compare().
Plugins that implement derived cListObject classes may need to adjust their
code.

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: config.c 1.127 2004/05/16 12:43:55 kls Exp $ * $Id: config.c 1.128 2004/10/31 16:17:39 kls Exp $
*/ */
#include "config.h" #include "config.h"
@ -193,19 +193,19 @@ cSetupLine::~cSetupLine()
free(value); free(value);
} }
bool cSetupLine::operator< (const cListObject &ListObject) int cSetupLine::Compare(const cListObject &ListObject) const
{ {
const cSetupLine *sl = (cSetupLine *)&ListObject; const cSetupLine *sl = (cSetupLine *)&ListObject;
if (!plugin && !sl->plugin) if (!plugin && !sl->plugin)
return strcasecmp(name, sl->name) < 0; return strcasecmp(name, sl->name);
if (!plugin) if (!plugin)
return true; return -1;
if (!sl->plugin) if (!sl->plugin)
return false; return 1;
int result = strcasecmp(plugin, sl->plugin); int result = strcasecmp(plugin, sl->plugin);
if (result == 0) if (result == 0)
result = strcasecmp(name, sl->name); result = strcasecmp(name, sl->name);
return result < 0; return result;
} }
bool cSetupLine::Parse(char *s) bool cSetupLine::Parse(char *s)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: config.h 1.202 2004/10/30 11:52:41 kls Exp $ * $Id: config.h 1.203 2004/10/31 16:17:02 kls Exp $
*/ */
#ifndef __CONFIG_H #ifndef __CONFIG_H
@ -185,7 +185,7 @@ public:
cSetupLine(void); cSetupLine(void);
cSetupLine(const char *Name, const char *Value, const char *Plugin = NULL); cSetupLine(const char *Name, const char *Value, const char *Plugin = NULL);
virtual ~cSetupLine(); virtual ~cSetupLine();
virtual bool operator< (const cListObject &ListObject); virtual int Compare(const cListObject &ListObject) const;
const char *Plugin(void) { return plugin; } const char *Plugin(void) { return plugin; }
const char *Name(void) { return name; } const char *Name(void) { return name; }
const char *Value(void) { return value; } const char *Value(void) { return value; }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: eitscan.c 1.22 2004/04/16 13:33:34 kls Exp $ * $Id: eitscan.c 1.23 2004/10/31 16:19:49 kls Exp $
*/ */
#include "eitscan.h" #include "eitscan.h"
@ -20,10 +20,10 @@ private:
cChannel channel; cChannel channel;
public: public:
cScanData(const cChannel *Channel); cScanData(const cChannel *Channel);
virtual bool operator< (const cListObject &ListObject); virtual int Compare(const cListObject &ListObject) const;
int Source(void) { return channel.Source(); } int Source(void) const { return channel.Source(); }
int Transponder(void) { return channel.Transponder(); } int Transponder(void) const { return channel.Transponder(); }
const cChannel *GetChannel(void) { return &channel; } const cChannel *GetChannel(void) const { return &channel; }
}; };
cScanData::cScanData(const cChannel *Channel) cScanData::cScanData(const cChannel *Channel)
@ -31,10 +31,13 @@ cScanData::cScanData(const cChannel *Channel)
channel = *Channel; channel = *Channel;
} }
bool cScanData::operator< (const cListObject &ListObject) int cScanData::Compare(const cListObject &ListObject) const
{ {
cScanData *sd = (cScanData *)&ListObject; const cScanData *sd = (const cScanData *)&ListObject;
return Source() < sd->Source() || Source() == sd->Source() && Transponder() < sd->Transponder(); int r = Source() - sd->Source();
if (r == 0)
r = Transponder() - sd->Transponder();
return r;
} }
// --- cScanList ------------------------------------------------------------- // --- cScanList -------------------------------------------------------------

6
epg.c
View File

@ -7,7 +7,7 @@
* Original version (as used in VDR before 1.3.0) written by * Original version (as used in VDR before 1.3.0) written by
* Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>. * Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>.
* *
* $Id: epg.c 1.20 2004/10/24 15:01:50 kls Exp $ * $Id: epg.c 1.21 2004/10/31 16:12:36 kls Exp $
*/ */
#include "epg.h" #include "epg.h"
@ -40,10 +40,10 @@ cEvent::~cEvent()
free(description); free(description);
} }
bool cEvent::operator< (const cListObject &ListObject) int cEvent::Compare(const cListObject &ListObject) const
{ {
cEvent *e = (cEvent *)&ListObject; cEvent *e = (cEvent *)&ListObject;
return startTime < e->startTime; return startTime - e->startTime;
} }
void cEvent::SetEventID(u_int16_t EventID) void cEvent::SetEventID(u_int16_t EventID)

4
epg.h
View File

@ -7,7 +7,7 @@
* Original version (as used in VDR before 1.3.0) written by * Original version (as used in VDR before 1.3.0) written by
* Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>. * Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>.
* *
* $Id: epg.h 1.16 2004/10/24 13:56:00 kls Exp $ * $Id: epg.h 1.17 2004/10/31 16:17:10 kls Exp $
*/ */
#ifndef __EPG_H #ifndef __EPG_H
@ -40,7 +40,7 @@ private:
public: public:
cEvent(tChannelID ChannelID, u_int16_t EventID); cEvent(tChannelID ChannelID, u_int16_t EventID);
~cEvent(); ~cEvent();
virtual bool operator< (const cListObject &ListObject); virtual int Compare(const cListObject &ListObject) const;
tChannelID ChannelID(void) const { return channelID; } tChannelID ChannelID(void) const { return channelID; }
u_int16_t EventID(void) const { return eventID; } u_int16_t EventID(void) const { return eventID; }
uchar TableID(void) const { return tableID; } uchar TableID(void) const { return tableID; }

8
menu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: menu.c 1.317 2004/10/31 12:53:00 kls Exp $ * $Id: menu.c 1.318 2004/11/01 10:40:38 kls Exp $
*/ */
#include "menu.h" #include "menu.h"
@ -667,7 +667,7 @@ private:
cTimer *timer; cTimer *timer;
public: public:
cMenuTimerItem(cTimer *Timer); cMenuTimerItem(cTimer *Timer);
virtual bool operator< (const cListObject &ListObject); virtual int Compare(const cListObject &ListObject) const;
virtual void Set(void); virtual void Set(void);
cTimer *Timer(void) { return timer; } cTimer *Timer(void) { return timer; }
}; };
@ -678,9 +678,9 @@ cMenuTimerItem::cMenuTimerItem(cTimer *Timer)
Set(); Set();
} }
bool cMenuTimerItem::operator< (const cListObject &ListObject) int cMenuTimerItem::Compare(const cListObject &ListObject) const
{ {
return *timer < *((cMenuTimerItem *)&ListObject)->timer; return timer->Compare(*((cMenuTimerItem *)&ListObject)->timer);
} }
void cMenuTimerItem::Set(void) void cMenuTimerItem::Set(void)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: recording.c 1.90 2004/10/31 10:09:36 kls Exp $ * $Id: recording.c 1.91 2004/10/31 16:22:33 kls Exp $
*/ */
#include "recording.h" #include "recording.h"
@ -451,7 +451,7 @@ char *cRecording::StripEpisodeName(char *s)
return s; return s;
} }
char *cRecording::SortName(void) char *cRecording::SortName(void) const
{ {
if (!sortBuffer) { if (!sortBuffer) {
char *s = StripEpisodeName(strdup(FileName() + strlen(VideoDirectory) + 1)); char *s = StripEpisodeName(strdup(FileName() + strlen(VideoDirectory) + 1));
@ -472,10 +472,10 @@ int cRecording::GetResume(void) const
return resume; return resume;
} }
bool cRecording::operator< (const cListObject &ListObject) int cRecording::Compare(const cListObject &ListObject) const
{ {
cRecording *r = (cRecording *)&ListObject; cRecording *r = (cRecording *)&ListObject;
return strcasecmp(SortName(), r->SortName()) < 0; return strcasecmp(SortName(), r->SortName());
} }
const char *cRecording::FileName(void) const const char *cRecording::FileName(void) const

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: recording.h 1.31 2004/07/17 11:09:49 kls Exp $ * $Id: recording.h 1.32 2004/10/31 16:24:38 kls Exp $
*/ */
#ifndef __RECORDING_H #ifndef __RECORDING_H
@ -36,12 +36,12 @@ class cRecording : public cListObject {
private: private:
mutable int resume; mutable int resume;
mutable char *titleBuffer; mutable char *titleBuffer;
char *sortBuffer; mutable char *sortBuffer;
mutable char *fileName; mutable char *fileName;
mutable char *name; mutable char *name;
char *summary; char *summary;
char *StripEpisodeName(char *s); static char *StripEpisodeName(char *s);
char *SortName(void); char *SortName(void) const;
int GetResume(void) const; int GetResume(void) const;
public: public:
time_t start; time_t start;
@ -50,7 +50,7 @@ public:
cRecording(cTimer *Timer, const char *Title, const char *Subtitle, const char *Summary); cRecording(cTimer *Timer, const char *Title, const char *Subtitle, const char *Summary);
cRecording(const char *FileName); cRecording(const char *FileName);
~cRecording(); ~cRecording();
virtual bool operator< (const cListObject &ListObject); virtual int Compare(const cListObject &ListObject) const;
const char *Name(void) const { return name; } const char *Name(void) const { return name; }
const char *FileName(void) const; const char *FileName(void) const;
const char *Title(char Delimiter = ' ', bool NewIndicator = false, int Level = -1) const; const char *Title(char Delimiter = ' ', bool NewIndicator = false, int Level = -1) const;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: timers.c 1.15 2004/10/31 10:07:43 kls Exp $ * $Id: timers.c 1.16 2004/10/31 16:41:30 kls Exp $
*/ */
#include "timers.h" #include "timers.h"
@ -95,12 +95,15 @@ cTimer& cTimer::operator= (const cTimer &Timer)
return *this; return *this;
} }
bool cTimer::operator< (const cListObject &ListObject) int cTimer::Compare(const cListObject &ListObject) const
{ {
cTimer *ti = (cTimer *)&ListObject; cTimer *ti = (cTimer *)&ListObject;
time_t t1 = StartTime(); time_t t1 = StartTime();
time_t t2 = ti->StartTime(); time_t t2 = ti->StartTime();
return t1 < t2 || (t1 == t2 && priority > ti->priority); int r = t1 - t2;
if (r == 0)
r = ti->priority - priority;
return r;
} }
const char *cTimer::ToText(bool UseChannelID) const char *cTimer::ToText(bool UseChannelID)
@ -248,25 +251,25 @@ bool cTimer::Save(FILE *f)
return fprintf(f, ToText(true)) > 0; return fprintf(f, ToText(true)) > 0;
} }
bool cTimer::IsSingleEvent(void) bool cTimer::IsSingleEvent(void) const
{ {
return (day & 0x80000000) == 0; return (day & 0x80000000) == 0;
} }
int cTimer::GetMDay(time_t t) int cTimer::GetMDay(time_t t) const
{ {
struct tm tm_r; struct tm tm_r;
return localtime_r(&t, &tm_r)->tm_mday; return localtime_r(&t, &tm_r)->tm_mday;
} }
int cTimer::GetWDay(time_t t) int cTimer::GetWDay(time_t t) const
{ {
struct tm tm_r; struct tm tm_r;
int weekday = localtime_r(&t, &tm_r)->tm_wday; int weekday = localtime_r(&t, &tm_r)->tm_wday;
return weekday == 0 ? 6 : weekday - 1; // we start with monday==0! return weekday == 0 ? 6 : weekday - 1; // we start with monday==0!
} }
bool cTimer::DayMatches(time_t t) bool cTimer::DayMatches(time_t t) const
{ {
return IsSingleEvent() ? GetMDay(t) == day : (day & (1 << GetWDay(t))) != 0; return IsSingleEvent() ? GetMDay(t) == day : (day & (1 << GetWDay(t))) != 0;
} }
@ -301,7 +304,7 @@ char *cTimer::SetFile(const char *File)
return file; return file;
} }
bool cTimer::Matches(time_t t, bool Directly) bool cTimer::Matches(time_t t, bool Directly) const
{ {
startTime = stopTime = 0; startTime = stopTime = 0;
if (t == 0) if (t == 0)
@ -363,14 +366,14 @@ int cTimer::Matches(const cEvent *Event)
return tmNone; return tmNone;
} }
time_t cTimer::StartTime(void) time_t cTimer::StartTime(void) const
{ {
if (!startTime) if (!startTime)
Matches(); Matches();
return startTime; return startTime;
} }
time_t cTimer::StopTime(void) time_t cTimer::StopTime(void) const
{ {
if (!stopTime) if (!stopTime)
Matches(); Matches();
@ -425,7 +428,7 @@ void cTimer::InvFlags(int Flags)
flags ^= Flags; flags ^= Flags;
} }
bool cTimer::HasFlags(int Flags) bool cTimer::HasFlags(int Flags) const
{ {
return (flags & Flags) == Flags; return (flags & Flags) == Flags;
} }
@ -506,7 +509,7 @@ cTimer *cTimers::GetNextActiveTimer(void)
{ {
cTimer *t0 = NULL; cTimer *t0 = NULL;
for (cTimer *ti = First(); ti; ti = Next(ti)) { for (cTimer *ti = First(); ti; ti = Next(ti)) {
if ((ti->HasFlags(tfActive)) && (!t0 || *ti < *t0)) if ((ti->HasFlags(tfActive)) && (!t0 || ti->Compare(*t0) < 0))
t0 = ti; t0 = ti;
} }
return t0; return t0;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: timers.h 1.9 2004/10/31 10:06:54 kls Exp $ * $Id: timers.h 1.10 2004/10/31 16:41:17 kls Exp $
*/ */
#ifndef __TIMERS_H #ifndef __TIMERS_H
@ -26,7 +26,7 @@ enum eTimerMatch { tmNone, tmPartial, tmFull };
class cTimer : public cListObject { class cTimer : public cListObject {
friend class cMenuEditTimer; friend class cMenuEditTimer;
private: private:
time_t startTime, stopTime; mutable time_t startTime, stopTime;
static char *buffer; static char *buffer;
bool recording, pending, inVpsMargin; bool recording, pending, inVpsMargin;
int flags; int flags;
@ -37,7 +37,7 @@ private:
int priority; int priority;
int lifetime; int lifetime;
char file[MaxFileName]; char file[MaxFileName];
time_t firstday; mutable time_t firstday;
char *summary; char *summary;
const cEvent *event; const cEvent *event;
public: public:
@ -45,7 +45,7 @@ public:
cTimer(const cEvent *Event); cTimer(const cEvent *Event);
virtual ~cTimer(); virtual ~cTimer();
cTimer& operator= (const cTimer &Timer); cTimer& operator= (const cTimer &Timer);
virtual bool operator< (const cListObject &ListObject); virtual int Compare(const cListObject &ListObject) const;
bool Recording(void) { return recording; } bool Recording(void) { return recording; }
bool Pending(void) { return pending; } bool Pending(void) { return pending; }
bool InVpsMargin(void) { return inVpsMargin; } bool InVpsMargin(void) { return inVpsMargin; }
@ -63,17 +63,17 @@ public:
const cEvent *Event(void) { return event; } const cEvent *Event(void) { return event; }
bool Parse(const char *s); bool Parse(const char *s);
bool Save(FILE *f); bool Save(FILE *f);
bool IsSingleEvent(void); bool IsSingleEvent(void) const;
int GetMDay(time_t t); int GetMDay(time_t t) const;
int GetWDay(time_t t); int GetWDay(time_t t) const;
bool DayMatches(time_t t); bool DayMatches(time_t t) const;
static time_t IncDay(time_t t, int Days); static time_t IncDay(time_t t, int Days);
static time_t SetTime(time_t t, int SecondsFromMidnight); static time_t SetTime(time_t t, int SecondsFromMidnight);
char *SetFile(const char *File); char *SetFile(const char *File);
bool Matches(time_t t = 0, bool Directly = false); bool Matches(time_t t = 0, bool Directly = false) const;
int Matches(const cEvent *Event); int Matches(const cEvent *Event);
time_t StartTime(void); time_t StartTime(void) const;
time_t StopTime(void); time_t StopTime(void) const;
void SetEvent(const cEvent *Event); void SetEvent(const cEvent *Event);
void SetRecording(bool Recording); void SetRecording(bool Recording);
void SetPending(bool Pending); void SetPending(bool Pending);
@ -81,7 +81,7 @@ public:
void SetFlags(int Flags); void SetFlags(int Flags);
void ClrFlags(int Flags); void ClrFlags(int Flags);
void InvFlags(int Flags); void InvFlags(int Flags);
bool HasFlags(int Flags); bool HasFlags(int Flags) const;
void Skip(void); void Skip(void);
void OnOff(void); void OnOff(void);
const char *PrintFirstDay(void); const char *PrintFirstDay(void);

37
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.c 1.80 2004/06/13 14:36:41 kls Exp $ * $Id: tools.c 1.81 2004/10/31 16:42:36 kls Exp $
*/ */
#include "tools.h" #include "tools.h"
@ -939,19 +939,28 @@ int cListBase::Count(void) const
return n; return n;
} }
void cListBase::Sort(void) static int CompareListObjects(const void *a, const void *b)
{ {
bool swapped; const cListObject *la = *(const cListObject **)a;
do { const cListObject *lb = *(const cListObject **)b;
swapped = false; return la->Compare(*lb);
cListObject *object = objects; }
while (object) {
if (object->Next() && *object->Next() < *object) { void cListBase::Sort(void)
Move(object->Next(), object); {
swapped = true; int n = Count();
} cListObject *a[n];
object = object->Next(); cListObject *object = objects;
} int i = 0;
} while (swapped); while (object && i < n) {
a[i++] = object;
object = object->Next();
}
qsort(a, n, sizeof(cListObject *), CompareListObjects);
objects = lastObject = NULL;
for (i = 0; i < n; i++) {
a[i]->Unlink();
Add(a[i]);
}
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.h 1.57 2004/06/13 14:13:26 kls Exp $ * $Id: tools.h 1.58 2004/10/31 16:16:37 kls Exp $
*/ */
#ifndef __TOOLS_H #ifndef __TOOLS_H
@ -148,7 +148,9 @@ private:
public: public:
cListObject(void); cListObject(void);
virtual ~cListObject(); virtual ~cListObject();
virtual bool operator< (const cListObject &ListObject) { return false; } virtual int Compare(const cListObject &ListObject) const { return 0; }
///< Must return 0 if this object is equal to ListObject, a positive value
///< if it is "greater", and a negative value if it is "smaller".
void Append(cListObject *Object); void Append(cListObject *Object);
void Insert(cListObject *Object); void Insert(cListObject *Object);
void Unlink(void); void Unlink(void);