diff options
author | root <root@lwg5001.(none)> | 2008-12-18 08:46:41 +0100 |
---|---|---|
committer | root <root@lwg5001.(none)> | 2008-12-18 08:46:41 +0100 |
commit | 0a38f9f8cde03a188c79f66dc4b005d83a6f0cfd (patch) | |
tree | ac9bcbdab8b2a3c23423d7dd14278cd6d77606de /readline.cpp | |
parent | f381118bd3f91740edc5bf464ab1300938f3ec5d (diff) | |
download | vdr-plugin-infosatepg-0a38f9f8cde03a188c79f66dc4b005d83a6f0cfd.tar.gz vdr-plugin-infosatepg-0a38f9f8cde03a188c79f66dc4b005d83a6f0cfd.tar.bz2 |
Initial commit
Diffstat (limited to 'readline.cpp')
-rw-r--r-- | readline.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/readline.cpp b/readline.cpp new file mode 100644 index 0000000..f13852e --- /dev/null +++ b/readline.cpp @@ -0,0 +1,70 @@ +/* + * readline.cpp: A plugin for the Video Disk Recorder + * + * See the README file for copyright information and how to reach the author. + * + * $Id$ + */ + +#include <stdlib.h> +#include <stdio.h> +#include "readline.h" + +// --- cReadLineInfosatepg --------------------------------------------------- + +cReadLineInfosatepg::cReadLineInfosatepg(void) +{ + buffer = NULL; +} + +cReadLineInfosatepg::~cReadLineInfosatepg() +{ + free(buffer); +} + +char *cReadLineInfosatepg::Read(FILE *f,size_t *size) +{ + free(buffer); buffer=NULL; + if ((!size) || (!f)) return NULL; + bool ext=false; + *size=0; + do + { + char *tempbuffer=NULL; + size_t tempsize=0; + + ext=false; + int n = getline(&tempbuffer, &tempsize, f); + if (n > 0) + { + if (tempbuffer[n-1] == '\n') + { + n--; + tempbuffer[n] = 0; + if (n > 0) + { + if (tempbuffer[n-1] == '\r') + n--; + tempbuffer[n] = 0; + } + } + if (n>0) + { + if (tempbuffer[n-1] == '\\') + { + n--; + tempbuffer[n]=0; + ext=true; + } + } + + buffer=(char*) realloc(buffer,*size+(n+1)); + snprintf(&buffer[*size],n+1,tempbuffer); + free(tempbuffer); + *size+=n; + } + } + while (ext==true); + + return buffer; +} |