cReadLine now dynamically allocates its buffer; changed cConfig::Load() to use cReadLine instead of a fixed buffer

This commit is contained in:
Klaus Schmidinger 2005-11-04 17:18:33 +01:00
parent 903e929a85
commit 92af12daac
5 changed files with 36 additions and 14 deletions

View File

@ -857,6 +857,7 @@ Christian Jacobsen <christian.jacobsen@stageholding.de>
Andreas Mair <Andreas.Mair@linogate.com>
for reporting a short display of the main menu if a plugin displays its own OSD and
is started through a user defined key macro
for reporting a problem with extremely long summary fields in timers
Olivier Jacques <jacquesolivier@hotmail.com>)
for translating OSD texts to the French language

View File

@ -3924,3 +3924,8 @@ Video Disk Recorder Revision History
Sascha Volkenandt).
- Fixed a memory leak in cString::operator=() (reported by Sascha Volkenandt).
- Updated the Dutch OSD texts (thanks to Maarten Wisse).
- cReadLine now dynamically allocates its buffer, so that it can handle lines
of any length.
- Changed cConfig::Load() to use cReadLine instead of a fixed buffer (thanks
to Andreas Mair for reporting a problem with extremely long summary fields
in timers).

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: config.h 1.233 2005/11/04 14:18:59 kls Exp $
* $Id: config.h 1.234 2005/11/04 15:55:05 kls Exp $
*/
#ifndef __CONFIG_H
@ -102,20 +102,21 @@ public:
isyslog("loading %s", fileName);
FILE *f = fopen(fileName, "r");
if (f) {
char *s;
int line = 0;
char buffer[MAXPARSEBUFFER];
cReadLine ReadLine;
result = true;
while (fgets(buffer, sizeof(buffer), f) > 0) {
while ((s = ReadLine.Read(f)) != NULL) {
line++;
if (allowComments) {
char *p = strchr(buffer, '#');
char *p = strchr(s, '#');
if (p)
*p = 0;
}
stripspace(buffer);
if (!isempty(buffer)) {
stripspace(s);
if (!isempty(s)) {
T *l = new T;
if (l->Parse(buffer))
if (l->Parse(s))
Add(l);
else {
esyslog("ERROR: error in %s, line %d", fileName, line);

22
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.c 1.102 2005/11/04 14:26:39 kls Exp $
* $Id: tools.c 1.103 2005/11/04 16:33:18 kls Exp $
*/
#include "tools.h"
@ -610,12 +610,24 @@ cString TimeString(time_t t)
// --- cReadLine -------------------------------------------------------------
cReadLine::cReadLine(void)
{
size = 0;
buffer = NULL;
}
cReadLine::~cReadLine()
{
free(buffer);
}
char *cReadLine::Read(FILE *f)
{
if (fgets(buffer, sizeof(buffer), f) > 0) {
int l = strlen(buffer) - 1;
if (l >= 0 && buffer[l] == '\n')
buffer[l] = 0;
int n = getline(&buffer, &size, f);
if (n > 0) {
n--;
if (buffer[n] == '\n')
buffer[n] = 0;
return buffer;
}
return NULL;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.h 1.81 2005/10/31 12:54:36 kls Exp $
* $Id: tools.h 1.82 2005/11/04 17:05:35 kls Exp $
*/
#ifndef __TOOLS_H
@ -135,8 +135,11 @@ public:
class cReadLine {
private:
char buffer[MAXPARSEBUFFER];
size_t size;
char *buffer;
public:
cReadLine(void);
~cReadLine();
char *Read(FILE *f);
};