SASC
DVBSoftCAM

misc.h

Go to the documentation of this file.
00001 /*
00002  * Softcam plugin to VDR (C++)
00003  *
00004  * This code is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This code is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
00018  */
00019 
00020 #ifndef ___MISC_H
00021 #define ___MISC_H
00022 
00023 #include <alloca.h>
00024 
00025 // ----------------------------------------------------------------
00026 
00027 #define WORD(buffer,index,mask) (((buffer[(index)]<<8) + buffer[(index)+1]) & mask)
00028 #define SCT_LEN(sct) (3+(((sct)[1]&0x0f)<<8)+(sct)[2])
00029 
00030 #define MBC(a,b)    (((a)<<8)+(b))
00031 #define ADDC3(ab,c) ((ab)+((c)<<16))
00032 #define MBC3(a,b,c) ADDC3(MBC((a),(b)),(c))
00033 #define C2(x)       (((x)>>8)&0xFF)
00034 #define C3(x)       (((x)>>16)&0xFF)
00035 #define C2MASK      0xFFFF
00036 
00037 // replacement for variable-sized arrays
00038 #define AUTOARRAY(type,size) (type *)alloca(sizeof(type)*(size))
00039 #define AUTOMEM(size)        (unsigned char *)alloca(size)
00040 
00041 // ----------------------------------------------------------------
00042 
00043 const char *HexStr(char *str, const unsigned char *mem, int len);
00044 #define KeyStr(str,key) HexStr(str,key,8)
00045 
00046 void SetSctLen(unsigned char *data, int len);
00047 
00048 int GetHex(const char * &line, unsigned char *store, int count, bool fixedLen=true);
00049 int GetHexAsc(const char * &line, unsigned char *store, int count);
00050 int GetChar(const char * &line, int *store, int count);
00051 unsigned long long Bin2LongLong(unsigned char *mem, int len);
00052 #define Bin2Int(mem,len) ((int)Bin2LongLong((mem),(len)))
00053 
00054 bool CheckNull(const unsigned char *data, int len);
00055 bool CheckFF(const unsigned char *data, int len);
00056 unsigned char XorSum(const unsigned char *mem, int len);
00057 unsigned int crc32_le(unsigned int crc, unsigned char const *p, int len);
00058 
00059 char *bprintf(const char *fmt, ...) __attribute__ ((format (printf,1,2)));
00060 
00061 // ----------------------------------------------------------------
00062 
00063 class cLineBuff {
00064 private:
00065   int blockSize;
00066   char *work;
00067   int blen, wlen;
00068   //
00069   bool Check(int num);
00070 protected:
00071   char *Grab(void);
00072 public:
00073   cLineBuff(int blocksize);
00074   ~cLineBuff();
00075   void Printf(const char *fmt, ...) __attribute__ ((format (printf,2,3)));
00076   void Strcat(const char *str);
00077   void Flush(void);
00078   void Back(int n);
00079   const char *Line(void) const { return work; }
00080   int Length(void) const { return blen; }
00081   };
00082 
00083 // ----------------------------------------------------------------
00084 
00085 class cSimpleListBase;
00086 
00087 class cSimpleItem {
00088 friend class cSimpleListBase;
00089 private:
00090   cSimpleItem *next;
00091 public:
00092   virtual ~cSimpleItem() {}
00093   cSimpleItem *Next(void) const { return next; }
00094   };
00095 
00096 class cSimpleListBase {
00097 protected:
00098   cSimpleItem *first, *last;
00099   int count;
00100 public:
00101   cSimpleListBase(void);
00102   ~cSimpleListBase();
00103   void Add(cSimpleItem *Item, cSimpleItem *After=0);
00104   void Ins(cSimpleItem *Item);
00105   void Del(cSimpleItem *Item, bool Del=true);
00106   void Clear(void);
00107   int Count(void) const { return count; }
00108   };
00109 
00110 template<class T> class cSimpleList : public cSimpleListBase {
00111 public:
00112   T *First(void) const { return (T *)first; }
00113   T *Last(void) const { return (T *)last; }
00114   T *Next(const T *item) const { return (T *)item->cSimpleItem::Next(); }
00115   };
00116 
00117 #endif //___MISC_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines